Skip to content

Conversation

@graalvmbot
Copy link
Collaborator

Serialized bytecode for code loaded from pyc files can now be unloaded from memory. Possible later reparsing will be able to fetch it again from the same pyc file, using an offset. To have confidence that we're actually reparsing the right file, I intrinsified a small part of _bootstrap_external. Only this code path allows unloading. If the pyc file is deleted or changed (detected by comparing the header, which by default is mtime+size), the reparsing fails with a SystemError. The reparsing happens when you use instrumentation (tagged or settrace/monitoring). Aso, the bytecode has to be realoaded when accessing co_code of a code object that was loaded from a pyc file. Note that this optimization has no effect when running from py files or frozen modules, only pyc files. Locally, I measured a 5% improvement on heap:import-a-lot.

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Jan 26, 2026
@graalvmbot graalvmbot closed this Jan 26, 2026
@graalvmbot graalvmbot deleted the msimacek/GR-71240_reparsing_pyc branch January 26, 2026 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants