Optimize/iterative traversal and scope caching#9
Merged
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Single quotes for strings, double quotes for docstrings - Type hints on all function signatures - X | Y unions, X | None instead of Optional - Native list, dict, tuple, set typing - StrEnum where applicable (DecoderType, _JSType) - Expanded abbreviated variable names - Imports at top of files, never inside functions - Reduced nesting via early returns and helper extraction - match statements replacing long if/elif chains Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The iterative-only traversal caused a 16% regression due to Python tuple allocation overhead. This adds recursive fast paths for enter-only visitors (all 46 call sites) and scope tree building, with automatic fallback to iterative traversal at depth > 500 to prevent stack overflow on deep ASTs. Benchmark: 2.95s mean (was 3.67s iterative-only, 3.17s original recursive). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Avoid redundant build_scope_tree() calls by caching the result in the deobfuscator loop and passing it to scope-using transforms. The cache is invalidated when any transform modifies the AST. Also add a lazy parent map (build_parent_map) to the base Transform class, replacing O(n) find_parent() tree walks with O(1) lookups. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…and parent map fix
- Replace isinstance(x, dict/list) with type(x) is dict/list in hot paths
of traverser.py and scope.py (pointer comparison vs MRO lookup)
- Convert node.get('type') to node['type'] where callers guarantee key exists
- Cache len() in _traverse_enter_only list iteration loop
- Fix parent map thrashing in class_static_resolver: build once before
traversal, pass parent info from enter callback, invalidate once after
Benchmark: 3.03s → 2.71s mean on sample.js. Output is byte-identical.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
018e8f6 to
4cc3a9c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.