Skip to content

Optimize repeated string hoisting#25

Draft
alvinwan wants to merge 4 commits intomainfrom
dev/alvin/optimize-string-hoisting
Draft

Optimize repeated string hoisting#25
alvinwan wants to merge 4 commits intomainfrom
dev/alvin/optimize-string-hoisting

Conversation

@alvinwan
Copy link
Copy Markdown
Owner

@alvinwan alvinwan commented Apr 9, 2026

Summary

  • optimize repeated string hoisting by collecting reserved names during the same scope walk that counts repeated strings
  • reuse those per-scope reserved names in the rewriter instead of rescanning each module, function, and class subtree
  • keep repeated-name aliasing on its simpler existing implementation after benchmarking showed that path did not improve overall runtime

Why

The repeated string hoisting pass was doing extra subtree scans to recover reserved names for each scope. That duplicated work on larger packages and made the pass more expensive than it needed to be.

Impact

The checked-in pyminifier fixture now minifies faster with identical output bytes. In an interleaved HEAD vs patched comparison on .bench-repos/pyminifier-tool/pyminifier, average runtime went from 454.1 ms to 400.0 ms and median runtime from 442.5 ms to 393.6 ms, with output unchanged at 31,332 bytes.

Validation

  • python3 -m py_compile pymini/pymini.py
  • .venv/bin/pytest

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