Code quality, Python 3.11 compat, and perf optimizations#11
Merged
Conversation
- Expand all short variable names (init, expr, stmt, prop, obj, args, etc.) - Add StrEnum for constant strings (BindingKind, node types, operators) - Replace if/elif chains with match statements (~20 files) - Reduce nesting via early exits and extracted helper functions - Add type hints to all function signatures using '|' union syntax - Add from __future__ import annotations to all modules - Add concise docstrings to every function, class, and method - Enforce single quotes for strings, double quotes for docstrings - Update tests to match renamed symbols and heuristic outputs Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> black && isort
The `type X = ...` syntax requires Python 3.12+, but CI tests on 3.11. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Revert IntEnum+match/case in traverser hot path back to plain int constants with if/elif (avoids enum dispatch overhead) - Revert sys.modules indirection in _run_pre_passes to direct calls - Remove BindingKind StrEnum; revert to plain string comparisons - Revert unnecessary variable renames (parser, __main__, _fast_to_dict) - Remove duplicate _write_output helpers; inline the I/O - Remove ~56 trivial docstrings that just restate function names - Restore sample.deobfuscated.js to match main (revert VariableRenamer behavioral change that renamed str→string, arr→array, etc.) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Profiled 525 files (25 regression + 500 random from dataset). Total time improved from 20.6s to 18.4s (11% faster). ConstantProp (30x faster on large files): - _find_and_remove_declarator did a full AST traversal per removed binding (O(n*k)). Batched into single pass with set lookup (O(n)). - vue.esm.browser.js: 0.561s → 0.012s for this transform alone. ExpressionSimplifier (2.2x faster): - Merged 5 separate traverse() calls into 2 (one combined pass for unary/binary/conditional/await/comma + one for method calls). _count_nodes: - Replaced callback-based simple_traverse with direct iterative loop, eliminating per-node function call overhead. _fast_to_dict (parser): - Converted recursive esprima-to-dict conversion to stack-based iteration to avoid recursion overhead on large ASTs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The coding standards commit added response-like, path-like, and other usage-based rename hints to VariableRenamer. Regenerate the expected output snapshot to match. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
Changes
Code quality (57 files)
__all__to__init__.py; acceptPathin public API signaturesPerformance optimizations
traverse()calls into 2 combined passes_count_nodes: replace callback-basedsimple_traversewith direct iterative loop_fast_to_dict(parser): convert recursive esprima-to-dict to stack-based iterationBenchmarks vs
main(525 files: 25 regression + 500 random dataset)Test plan
🤖 Generated with Claude Code