Skip to content

Skip clearAnnotation AST walk in MapGenerator.generate for parsed roots with no comments #72

@alanzabihi

Description

@alanzabihi

Hypothesis

Even with thesis #42 merged (bypass MapGenerator when no source map), MapGenerator.generate() is still called when source maps are present or when the fast-path conditions dont apply. In that case, clearAnnotation() (map-generator.js:65-88) walks the entire root.nodes array backwards looking for sourceMappingURL comments.

For Workload B, the generated CSS files have no source map annotations. The clearAnnotation walk is always fruitless but still iterates all children of root.

Add a fast-path check: if root.nodes has no Comment children (or all comments dont start with # sourceMappingURL=), skip the walk. Since the benchmark generates files without source map annotations, this check would be O(1) for the common case.

Better yet, track during parsing whether any source map comment was found. Set a flag on Root: root._hasSourceMapComment. clearAnnotation checks this flag before walking.

Editable surface

  • lib/map-generator.js — skip clearAnnotation when no source map comments present
  • lib/parser.js — set _hasSourceMapComment flag on Root during parsing (optional)

What's different from prior work

Expected impact

METRIC_B improvement of 1-3ms. clearAnnotation walk eliminated for 250 files.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions