mirror of
https://github.com/morluto/rea
synced 2026-10-26 14:25:49 -04:00
fix(javascript): yield during the largest AST traversals (#1545)
After #1542 the longest event-loop blocks on large bundles were single AST traversals inside one analyzer: member-mutation collection with its fixpoint, static source analysis, and function fingerprints, each about one second on Obsidian's 3.7 MB app.js. - traverseJavaScriptAstSteps yields every 1,024 visited nodes with the same visit order; traverseJavaScriptAst drains it, so every existing caller is unchanged. - Member mutations, static analysis and fingerprints run as steps. The member-mutation fixpoint yields every 64 references, and fingerprints yield between callables. - The now-unused synchronous member-mutation and fingerprint wrappers are removed. Graph IDs and complete result digests match main on three inputs, including obsidian.asar. Over two runs there, the longest block falls from about 920 ms to 740 ms, the second from 860 to 595 ms, and blocks over 250 ms from 27 to 18, with total time within 1.5%. Refs #1462 Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import * as t from "@babel/types";
|
||||
|
||||
import { traverseJavaScriptAst } from "./javascriptSemanticTraversal.js";
|
||||
import {
|
||||
completeSemanticSteps,
|
||||
traverseJavaScriptAstSteps,
|
||||
} from "./javascriptSemanticTraversal.js";
|
||||
|
||||
import { inspectElectronStaticNode } from "./electronStaticAnalysis.js";
|
||||
import {
|
||||
@@ -57,9 +60,19 @@ export const analyzeParsedJavaScriptStaticSource = (
|
||||
source: string,
|
||||
file: ParsedJavaScriptSource,
|
||||
openReceiverFacts?: ReadonlyMap<number, JavaScriptOpenReceiverFact>,
|
||||
): JavaScriptStaticAnalysis => {
|
||||
): JavaScriptStaticAnalysis =>
|
||||
completeSemanticSteps(
|
||||
analyzeParsedJavaScriptStaticSourceSteps(source, file, openReceiverFacts),
|
||||
);
|
||||
|
||||
/** Static analysis that yields during its source traversal; results are unchanged. */
|
||||
export function* analyzeParsedJavaScriptStaticSourceSteps(
|
||||
source: string,
|
||||
file: ParsedJavaScriptSource,
|
||||
openReceiverFacts?: ReadonlyMap<number, JavaScriptOpenReceiverFact>,
|
||||
): Generator<void, JavaScriptStaticAnalysis> {
|
||||
const accumulator = createJavaScriptAnalysisAccumulator(source.length);
|
||||
traverseStaticSource(file, {
|
||||
yield* traverseStaticSourceSteps(file, {
|
||||
source,
|
||||
accumulator,
|
||||
...(openReceiverFacts === undefined ? {} : { openReceiverFacts }),
|
||||
@@ -67,20 +80,20 @@ export const analyzeParsedJavaScriptStaticSource = (
|
||||
});
|
||||
addSourceMapDirectives(source, file.comments ?? [], accumulator);
|
||||
return finalizeStaticAnalysis(source, file, accumulator);
|
||||
};
|
||||
}
|
||||
|
||||
const traverseStaticSource = (
|
||||
function* traverseStaticSourceSteps(
|
||||
file: ParsedJavaScriptSource,
|
||||
findings: JavaScriptFindingContext,
|
||||
): void => {
|
||||
traverseJavaScriptAst(file, {
|
||||
): Generator<void, void> {
|
||||
yield* traverseJavaScriptAstSteps(file, {
|
||||
enter: (node) => {
|
||||
findings.accumulator.visitedNodes += 1;
|
||||
inspectNode(node, findings);
|
||||
return undefined;
|
||||
},
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
const finalizeStaticAnalysis = (
|
||||
source: string,
|
||||
|
||||
Reference in New Issue
Block a user