Skip to content

perf: merge RemarkAttacher double tree walk into single pass#294

Closed
ronaldtse wants to merge 2 commits into
mainfrom
chore/update-parsanol-1.3.9
Closed

perf: merge RemarkAttacher double tree walk into single pass#294
ronaldtse wants to merge 2 commits into
mainfrom
chore/update-parsanol-1.3.9

Conversation

@ronaldtse
Copy link
Copy Markdown
Contributor

Summary

  • Merged duplicate collect_nodes_with_positions tree walk in RemarkAttacher
  • attach() now builds the sorted nodes array once and reuses it for both tagged and untagged remark passes
  • Estimated ~215MB memory saving per large parse (math_functions_schema ~430MB → ~215MB)

Test plan

  • 1342 tests pass locally
  • RuboCop passes
  • GHA passes

attach() now calls build_sorted_nodes_with_positions() once and
passes the result to both attach_tagged_remarks() and
attach_untagged_remarks(), eliminating the duplicate tree walk.

Before: 2 × collect_nodes_with_positions() + 2 × sort (381K nodes each)
After:  1 × collect_nodes_with_positions() + 1 × sort

This was the largest memory overhead in remark attachment (~430MB
for math_functions_schema). Estimated ~215MB saving per large parse.
The same array of child collection attribute names was hardcoded in two
places: calculate_children_end_line and collect_children. Extracted to a
CHILD_COLLECTION_ATTRIBUTES constant to eliminate duplication and make
future maintenance easier.
@ronaldtse ronaldtse closed this Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant