Skip to content

Add empty tuple optimization #1178

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

Merged
merged 2 commits into from
Jul 25, 2019
Merged

Add empty tuple optimization #1178

merged 2 commits into from
Jul 25, 2019

Conversation

coolreader18
Copy link
Member

Yeah, not all that big of an optimization, but it seemed dumb to be allocating a new Rc for something that's essentially empty.

@coolreader18 coolreader18 force-pushed the coolreader18/empty-tuple branch from 9f3a26e to dfa66b0 Compare July 25, 2019 06:35
@windelbouwman
Copy link
Contributor

Hmm, this is interesting, and I would rather not do this. But actually this solves this example:

>>> a = ()
>>> b = ()
>>> a is b
True

Please add a test snippet for this special case.

src/main.rs Outdated
@@ -318,7 +318,7 @@ fn run_command(vm: &VirtualMachine, source: String) -> PyResult<()> {

fn run_module(vm: &VirtualMachine, module: &str) -> PyResult<()> {
debug!("Running module {}", module);
vm.import(module, &vm.ctx.new_tuple(vec![]), 0)?;
vm.import(module, &vm.ctx.empty_tuple(), 0)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please do not use this empty tuple directly, and make it a private method on PyContext. I think it is better to call the new_tuple function with an empty vector, so we have one way to create a tuple.

@@ -604,6 +609,10 @@ impl PyContext {
self.not_implemented.clone().into_object()
}

pub fn empty_tuple(&self) -> PyObjectRef {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this method could be private, or merged into the new_tuple function.

@coolreader18 coolreader18 force-pushed the coolreader18/empty-tuple branch from dfa66b0 to 8aee745 Compare July 25, 2019 14:28
@windelbouwman windelbouwman merged commit c998549 into master Jul 25, 2019
@coolreader18 coolreader18 deleted the coolreader18/empty-tuple branch August 2, 2019 18:48
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.

2 participants