8000 [codex] improve package-mode compression by alvinwan · Pull Request #13 · alvinwan/pymini · GitHub
[go: up one dir, main page]

Skip to content

[codex] improve package-mode compression - #13

Merged
alvinwan merged 1 commit into
mainfrom
dev/alvin/compress-more
Apr 5, 2026
Merged

alvinwan merged 1 commit into
mainfrom
dev/alvin/compress-more

Conversation

@alvinwan
@alvinwan alvinwan commented Apr 5, 2026
Copy link
Copy Markdown
Owner

Summary

This PR pushes package-mode compression further while keeping the validated TexSoup package path working.

  • add --rename-arguments to the CLI and API
  • use module-local reserved-name allocation in package mode instead of a single whole-repo reservation set
  • rename profitable top-level public globals while preserving the public API through aliases
  • rename method receivers like self/cls and rewrite safe internal keyword call sites
  • refresh the checked-in example output and benchmark docs to the current aggressive package settings

Why

The current package-mode compression still left easy wins on the table:

  • globally reserving names across the whole repo blocked short names that were only unsafe in other modules
  • preserve mode still kept many profitable module-level globals unchanged
  • argument names, especially self/cls, were still left long even under the aggressive settings

This keeps bundle mode unchanged and focuses on package mode, which is the validated path for TexSoup.

Impact

Current measured results with --rename-modules --rename-global-variables --rename-arguments:

  • tests/examples/pyminifier.py: 1,355 -> 438 bytes (67.7%)
  • tests/examples/pyminify.py: 1,990 -> 935 bytes (53.0%)
  • TexSoup/*.py: 98,181 -> 24,722 bytes (74.8%)
  • TexSoup.tar.gz: 23,656 -> 9,208 bytes (61.1%)

Validation

  • PYTHONPATH=. .venv/bin/python -m pytest
  • PYTHONPATH=. .venv/bin/python scripts/regenerate_examples.py --check
  • PYTHONPATH=. .venv/bin/python -m pymini package /tmp/pymini-texsoup-repo/TexSoup -o /tmp/pymini-texsoup-pass/TexSoup --rename-modules --rename-global-variables --rename-arguments
  • PYTHONPATH=/tmp/pymini-texsoup-pass:/tmp/pymini-texsoup-repo/tests .venv/bin/python -m pytest /tmp/pymini-texsoup-repo/tests -o addopts=''

Upstream TexSoup still passes with 78 tests green.

@alvinwan
alvinwan marked this pull request as ready for review April 5, 2026 12:23
@alvinwan
alvinwan merged commit e5d52ab into main Apr 5, 2026
10 checks passed
@alvinwan
alvinwan deleted the dev/alvin/compress-more branch April 5, 2026 12:23
@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 53d996504c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread pymini/pymini.py
Comment on lines 560 to +562
def _is_active_parameter_name(self, name):
if self.rename_arguments:
return False
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep parameter bindings active when argument renaming is enabled

Returning early from _is_active_parameter_name whenever rename_arguments is true makes assignment targets for unrenamed parameters look like ordinary locals, so _rename_assignment_target can create a new mapping and break control-flow semantics. For example, def f(x, flag):\n if flag: x = 2\n return x is transformed so the return reads a different name that is only conditionally assigned, raising UnboundLocalError when flag is false.

Useful? React with 👍 / 👎.

Comment thread pymini/pymini.py
Comment on lines 898 to 899
elif base_name in self.class_member_mappings:
attribute_mapping = self.class_member_mappings[base_name]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Rewrite renamed method attributes on local instance variables

Attribute remapping now only consults class names and receiver names, so calls through local instance variables are no longer updated after method renaming. With default keep_global_variables=False, a class method like test can be renamed in the class body while instance.test(...) is left unchanged, which fails at runtime with AttributeError because the renamed class no longer has test.

Useful? React with 👍 / 👎.

Comment thread pymini/pymini.py
Comment on lines +412 to 414
base_name = func.value.id if isinstance(func.value, ast.Name) else None
if base_name is None:
return None
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Resolve argument info for constructor-call method invocations

_call_argument_info now returns metadata only when func.value is an ast.Name, so calls like C().method(long_value=1) have no argument rewrite info. When rename_arguments=True renames method parameters, these constructor-call keywords stay on the old names and raise TypeError (unexpected keyword argument) at runtime.

Useful? React with 👍 / 👎.

Comment thread pymini/pymini.py
Comment on lines +1513 to +1514
if imported_name != alias.name and imported_name in self.callable_argument_infos:
self.callable_argument_infos[alias.name] = self.callable_argument_infos.pop(imported_name)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep callable arg metadata keyed by import alias names

When an imported symbol is renamed and also has an as alias, this block moves callable argument metadata from the local alias name to the imported symbol name. That loses rewrite metadata for actual call sites (which use the alias), so from main import square as g followed by g(long_value=1) is left unrevised and fails once square's parameter is renamed.

Useful? React with 👍 / 👎.

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

0