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

Static None #3

Closed
wants to merge 2 commits into from
Closed

Static None #3

wants to merge 2 commits into from

Conversation

catharinejm
Copy link
Collaborator

Minor optimization:

Rather than dealing with Box<Option<T>>, which requires a fresh allocation for everything, we can pretend to store Option<Box<T>>. We allocate a single static object, denoted EMPTY, and store its address when the channel is empty. Then, when we load the address, if it matches EMPTY we return None, otherwise we convert the pointer to a Box<T> and return Some(...) containing the box.

no allocation necessary for None
@catharinejm catharinejm changed the base branch from jd/boxit to master September 2, 2018 14:19
@catharinejm
Copy link
Collaborator Author

I'm gonna close this. The merge conflict is pretty extensive, and honestly this is probably a useless optimization. Based on rust-lang/rust#6001 and rust-lang/rust#1271, the compiler is already doing something similar. At some point we can profile some running code to see whether it makes needless allocations in practice or not.

@catharinejm catharinejm closed this Sep 2, 2018
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