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

Micro-optimization: use tuples instead of lists for conditions #228

Merged
merged 1 commit into from
Apr 6, 2021

Conversation

nat-n
Copy link
Collaborator

@nat-n nat-n commented Apr 5, 2021

This should give a small speed boost to some critical code paths.

The benchmark suite says it's not worse... (though it's not very sensitive).

According to some internets, tuple creation in these situations is ~5x faster than list creation: e.g. http://zwmiller.com/blogs/python_data_structure_speed.html

       before           after         ratio
     [7c5ee47e]       [58d5aa2f]
     <master>         <use_tuples>
      1.62±0.04μs      1.61±0.08μs     0.99  benchmarks.BenchMessage.time_attribute_access
       8.60±0.3μs       8.71±0.2μs     1.01  benchmarks.BenchMessage.time_attribute_setting
       14.4±0.7μs       13.8±0.3μs     0.96  benchmarks.BenchMessage.time_init_with_values
       14.0±0.5μs       13.3±0.5μs     0.95  benchmarks.BenchMessage.time_instantiation
         370±10μs         344±10μs     0.93  benchmarks.BenchMessage.time_overhead
       22.7±0.3μs         21.1±1μs     0.93  benchmarks.BenchMessage.time_serialize
              424              424     1.00  benchmarks.MemSuite.mem_instance

This should give a small speed boost to some critical code paths.
@nat-n nat-n requested a review from cetanu April 5, 2021 21:13
@cetanu
Copy link
Collaborator

cetanu commented Apr 6, 2021

Nice. I'm a fan of this in general.

@cetanu cetanu merged commit 5b639c8 into master Apr 6, 2021
@cetanu cetanu deleted the use_tuples branch April 6, 2021 00:40
@nat-n nat-n mentioned this pull request Apr 6, 2021
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