The Wayback Machine - https://web.archive.org/web/20211014201024/https://github.com/RustPython/RustPython/issues/2872
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

[RFC] Replace Option<int> with optional::Optioned<int> #2872

Open
youknowone opened this issue Aug 12, 2021 · 1 comment
Open

[RFC] Replace Option<int> with optional::Optioned<int> #2872

youknowone opened this issue Aug 12, 2021 · 1 comment
Labels

Comments

@youknowone
Copy link
Member

@youknowone youknowone commented Aug 12, 2021

Summary

Replace Option<int> with optional::Optioned<int> in native objects to save memory to enhance performance.

Detailed Explanation

In many cases, our usize means u63/u31 rather than u32/u64 because sys.maxsize is isize::MAX.
Unfortunately, we are not telling this to compiler very well.
For example, Option<usize> for None or u63 is a common type in RustPython. But its memory size if 16 rather than 8
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=cdbd4b4bcc01d81b57f8d9040901e107

By replacing it to optional::Optioned<usize>, it will go back to 8, the proper size of its actual representation.
https://docs.rs/optional/

Drawbacks, Rationale, and Alternatives

Unresolved Questions

@youknowone youknowone added the RFC label Aug 12, 2021
@whjpji
Copy link
Contributor

@whjpji whjpji commented Aug 19, 2021

Maybe it needs a benchmark?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants