-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-126703: Add freelists for small size lists #129921
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
base: main
Are you sure you want to change the base?
Conversation
c8f9ca3
to
b81c62f
Compare
To determine how well the freelist works here are some statistics. For each allocation type (e.g. allocate via the small list freelist, the normal freelist or a normal allocatie) we keep track of the size of the allocated list. We run the pyperformance benchmark and plot the resulting allocations as a histogram. We see that most allocations are for small lists. The funny parabola like shape is probably due to one of the benchmarks. We zoom into the region of small lists. Most allocations for small sizes are now via the new freelist.. For the deallocations we have similar results (here the split is only between the small list pushes and other). Finally, we look at the distribution of list resizes. Most resizes are to small lists. The resize implementation results in certain sizes being used more often (best visible for size > 30), but this also holds for smaller sizes (keep in mind we are using a log scale) The branch used to generate the statistics is https://github.com/eendebakpt/cpython/tree/small_list_freelist_statistics |
This adds a slight bit more complexity than the other implementations. Could you ping Mike Droetboom on Monday to benchmark this on the bench runner please? |
@mdboom Would you be able to run the performance benchmarks on this PR? Thanks |
No speedup nor slowdown (it's within noise) on the benchmark runner https://github.com/faster-cpython/benchmarking-public/tree/main/results/bm-20250408-3.14.0a7+-77f3e29 |
Thanks for running the benchmarks. The most improved benchmark (fannkuch) uses lists, the other improved benchmarks do not always involve lists so the overall performance change indeed seems to be neutral. I have some more statistics gathered at freelist_stats.md. They show a clear distinction between the freelists for even list size and odd list size (probably this is related to the allocation strategy). |
Sorry, this flew under my radar. Looks like @brandtbucher kicked these off for you, though. |
We add freelists for all lists of small length. The advantage over the existing freelist for lists is that we do not need to allocate and deallocate the
ob_item
field.Microbenchmarks show good results:
(Linux, PGO, tail calling interpreter). Pyperformance results are a 1% improvement, but this might be due to my unstable machine.
Pyperformance result
Benchmark script
Open questions:
ob_item
elements?