Sitelet https://web.archive.org/web/20230316093702/https://github.com/RustPython/RustPython/pull/4608
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework frozen modules and directly deserialize to CodeObject<Literal> #4608

Merged
merged 1 commit into from Mar 9, 2023

Conversation

coolreader18
Copy link
Member

Now frozen modules are stored as lz4-compressed in static memory until they are imported, which should help with memory usage in a freeze-stdlib environment (and the size increase from less efficient(?) compression due to potentially less dict-sharing(?? i have no clue how compression algorithms actually work) should hopefully not be too bad)

@coolreader18 coolreader18 force-pushed the bag-deser branch 3 times, most recently from 59488d9 to d9dd7ce Compare March 2, 2023 23:15

let output = quote! {
#crate_name::CodeObject::from_bytes(#bytes)
.expect("Deserializing CodeObject failed")
#crate_name::frozen_lib::FrozenCodeObject { bytes: &#bytes[..] }
Copy link
Member

@youknowone youknowone Mar 4, 2023 •

Choose a reason for hiding this comment

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

In my opinion, the name py_compile doesn't imply its result will be compressed but getting code object directly.
Renaming or making a new macro?

Copy link
Member Author

Choose a reason for hiding this comment

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

Perhaps, yeah, but because vm.ctx.new_code() still accepts it, it won't actually make a difference for users.

Copy link
Member

Choose a reason for hiding this comment

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

Users will expanse unexpected compression cost after this change.
I expect vm.compile and py_compile! are doing similar things because they use the same term.

one of my suggestion is, renaming current py_freeze to py_freeze_module and renaming py_compile to py_freeze.

Copy link
Member Author

Choose a reason for hiding this comment

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

They already were - the old CodeObject::from_bytes also did lz4 decompression, and py_compile!() just generated CodeObject::from_bytes(b"..."). I don't think compile returning a frozen code object is necessarily unintuitive (they're expecting it to compile it at build time and embed it in the binary; what's that if not freezing?) and again, since it's still accepted in the same places as before it doesn't actually make much of a difference to the user

Copy link
Member

@youknowone youknowone left a comment

Choose a reason for hiding this comment

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

I really like the changes.

compiler/core/src/bytecode.rs Outdated Show resolved Hide resolved
pub code: CodeObject<ConstantData>,
pub package: bool,
}

pub mod frozen_lib {
Copy link
Member

Choose a reason for hiding this comment

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

this is going bigger. maybe frozen_lib.rs later

derive-impl/src/compile_bytecode.rs Outdated Show resolved Hide resolved
@youknowone youknowone merged commit 87728c4 into RustPython:main Mar 9, 2023
13 checks passed
@coolreader18 coolreader18 deleted the bag-deser branch March 9, 2023 20:57
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.

None yet

2 participants