Skip to content

Optimize include parsing with per-file caching#19

Merged
revarbat merged 3 commits into
mainfrom
optimize-include-parsing
Jun 21, 2026
Merged

Optimize include parsing with per-file caching#19
revarbat merged 3 commits into
mainfrom
optimize-include-parsing

Conversation

@revarbat

Copy link
Copy Markdown
Member

Summary

  • Parse each included file independently instead of concatenating all sources into one giant string, enabling granular caching and faster individual parses
  • Add disk-based AST cache (pickle) so subsequent parses of unchanged files (e.g., BOSL2) load in ~1s instead of 45+s
  • Replace O(n²) recursive _get_node_end_position with Arpeggio's built-in position_end attribute
  • Fix _replace_text line count when strip_trailing_newline crosses a line boundary

Performance

Scenario Before After
Cold parse (first ever) 54.5s 46.7s
Subsequent parses (disk cache) 54.5s 1.0s
Same-process repeat (memory cache) instant instant

Test plan

  • All 957 existing tests pass
  • Include/use tests pass (test_use_include.py)
  • AST convenience tests pass (test_ast_convenience.py) — caching, invalidation, include processing
  • Verified BOSL2/std.scad produces correct AST (1306 nodes, 0 unresolved IncludeStatements)
  • process_includes=False correctly preserves IncludeStatement nodes

🤖 Generated with Claude Code

revarbat and others added 3 commits June 20, 2026 23:58
…ne boundary

The line_count_adjustment was subtracted instead of added, causing segments
after include replacements to report line numbers off by the number of
stripped trailing newlines. Also handle the case where the stripped newline
is the only line crossing (start_column should reset to 1).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Parse each included file independently instead of concatenating all
sources into one giant string. Each file's AST is cached to disk
(pickle) so subsequent parses of unchanged files load in ~1s instead
of 45+s. Also replace the O(n²) recursive _get_node_end_position with
Arpeggio's built-in position_end attribute.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@revarbat revarbat merged commit 6f72fe2 into main Jun 21, 2026
6 checks passed
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