mirror of
https://github.com/morluto/rea.git
synced 2026-11-23 06:55:55 +00:00
perf(artifacts/contracts): replace O(N^2) scans with hash joins/sweep-line and hoist expandToolAvailability group maps (#13585)
* perf(artifacts/contracts): replace O(N^2) scans with hash joins/sweep-line and hoist expandToolAvailability group maps * perf(dotnet): retain bounded bundle configuration scans
This commit is contained in:
1 parent
b6276368ee
commit
afad95fc91
3 files changed
+45
-30
No files matched your search
@@ -86,16 +86,28 @@ interface WrittenSegment {
|
||||
|
||||
/** The segments region boundaries cut, kept where some region covers them. */
|
||||
const coveredSegments = (ranges: readonly FileRange[]): WrittenSegment[] => {
|
||||
const cuts = [
|
||||
...new Set(ranges.flatMap(({ start, length }) => [start, start + length])),
|
||||
].sort((left, right) => left - right);
|
||||
return cuts.slice(1).flatMap((end, index) => {
|
||||
const deltas = new Map<number, number>();
|
||||
for (const { start, length } of ranges) {
|
||||
if (length <= 0) continue;
|
||||
deltas.set(start, (deltas.get(start) ?? 0) + 1);
|
||||
deltas.set(start + length, (deltas.get(start + length) ?? 0) - 1);
|
||||
}
|
||||
const cuts = [...deltas.keys()].sort((left, right) => left - right);
|
||||
const segments: WrittenSegment[] = [];
|
||||
let active = 0;
|
||||
for (let index = 0; index + 1 < cuts.length; index += 1) {
|
||||
const start = cuts[index]!;
|
||||
const covered = ranges.some(
|
||||
(range) => range.start <= start && end <= range.start + range.length,
|
||||
);
|
||||
return covered ? [{ start, end, first: -1, last: -1, bytes: 0 }] : [];
|
||||
});
|
||||
active += deltas.get(start) ?? 0;
|
||||
if (active > 0)
|
||||
segments.push({
|
||||
start,
|
||||
end: cuts[index + 1]!,
|
||||
first: -1,
|
||||
last: -1,
|
||||
bytes: 0,
|
||||
});
|
||||
}
|
||||
return segments;
|
||||
};
|
||||
|
||||
const tally = (
|
||||
|
||||
@@ -284,7 +284,8 @@ export function* captureDom(
|
||||
const { nodeType, nodeName, nodeValue, parent, attributes } =
|
||||
admitted.value;
|
||||
const nodeIndex = baseIndex + index;
|
||||
const attributeNames = [...new Set(attributes.map(([name]) => name))];
|
||||
const attributeSet = new Set(attributes.map(([name]) => name));
|
||||
const attributeNames = [...attributeSet];
|
||||
const domElement = domXmlElement(ancestry, index);
|
||||
const htmlTagName = domHtmlTagName(nodeName, domElement);
|
||||
if (domElement.xmlDocument === undefined)
|
||||
@@ -293,8 +294,8 @@ export function* captureDom(
|
||||
if (
|
||||
domElement.xmlDocument === false &&
|
||||
nodeType === 1 &&
|
||||
attributeNames.includes("xlink:href") &&
|
||||
!attributeNames.includes("href")
|
||||
attributeSet.has("xlink:href") &&
|
||||
!attributeSet.has("href")
|
||||
) {
|
||||
const backendNodeId = backendNodeIds[index];
|
||||
svgQuery =
|
||||
|
||||
@@ -604,28 +604,30 @@ export function expandToolAvailability(
|
||||
group.client_requirements ?? inventory.client_requirements,
|
||||
})),
|
||||
);
|
||||
return inventory.groups.flatMap((group) =>
|
||||
group.names.map((name) =>
|
||||
return inventory.groups.flatMap((group) => {
|
||||
const effectSet = new Set(group.effects);
|
||||
const annotationSet = new Set(group.annotations);
|
||||
const effects = Object.fromEntries(
|
||||
TOOL_EFFECT_NAMES.map((effect) => [effect, effectSet.has(effect)]),
|
||||
);
|
||||
const annotations = Object.fromEntries(
|
||||
TOOL_ANNOTATION_NAMES.map((annotation) => [
|
||||
annotation,
|
||||
annotationSet.has(annotation),
|
||||
]),
|
||||
);
|
||||
const client_requirements =
|
||||
group.client_requirements ?? inventory.client_requirements;
|
||||
return group.names.map((name) =>
|
||||
toolAvailability.parse({
|
||||
...group,
|
||||
name,
|
||||
client_requirements:
|
||||
group.client_requirements ?? inventory.client_requirements,
|
||||
effects: Object.fromEntries(
|
||||
TOOL_EFFECT_NAMES.map((effect) => [
|
||||
effect,
|
||||
group.effects.includes(effect),
|
||||
]),
|
||||
),
|
||||
annotations: Object.fromEntries(
|
||||
TOOL_ANNOTATION_NAMES.map((annotation) => [
|
||||
annotation,
|
||||
group.annotations.includes(annotation),
|
||||
]),
|
||||
),
|
||||
client_requirements,
|
||||
effects,
|
||||
annotations,
|
||||
}),
|
||||
),
|
||||
);
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/** Session status facts shared by every detail level and session kind. */
|
||||
|
||||
Reference in new issue
Block a user