GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-126703: add freelist for PyComplexObject's by skirpichev · Pull Request #135233 · python/cpython Conversation
|
| Benchmark | ref | patch |
|---|---|---|
| a+b | 223 ns | 198 ns: 1.13x faster |
| a*b | 236 ns | 209 ns: 1.13x faster |
| Geometric mean | (ref) | 1.13x faster |
# bench.py import pyperf from operator import add, mul runner = pyperf.Runner() a,b = 1+2j, -7+1.1j runner.bench_func('a+b', add, a, b) runner.bench_func('a*b', mul, a, b)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@skirpichev Would you like to provide benchmark enhancement for this change? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Oops, I just forgot to post one. Description updated. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Please share the pyperformance benchmark results. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Well, it shouldn't be affected. This collection has no benchmarks for complex math at all:
Probably less than floats, but not too much. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
AFAICS, real-world workloads that don't use complex numbers will pay the price of:
In applications that do use complex numbers, is it likely that they need to create/destroy them quickly? To review this I'll need to teach myself about Python's freelists; I can do that next week. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
I believe that we use pyperformance benchmark as the real world proxy. So if there is no benchmark for it, I am unsure. At least someone needs to share the benchmark for this. If not, people will add new PR for other built-in types with a microbenchmark, which would not be worth adding. We need criteria for this. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Yes, just a new empty
That happens in every arithmetic operation. Here is a benchmark with a simple sin() implementation:
Details# bench2.py def mysin(z): i, lasts, s, fact, num, sign = 1, 0, z, 1, z, 1 while s != lasts: lasts = s i += 2 fact *= i*(i-1) num *= z*z sign *= -1 s += num/fact*sign return s import pyperf runner = pyperf.Runner() runner.bench_func('mysin(1j)', mysin, 1j) runner.bench_func('mysin(1+1j)', mysin, 1+1j)
You are not alone, this is new for me as well :D IIUC (see help topic), this technique is not something, allowed for external C extensions.
I doubt we have too much built-in types. Being a built-in type is a sign from the real world too ;-) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I see this as a PR that speeds up complex numbers, not “X% of Python's real-world usage”. And that's fine.
Why shouldn't the criteria be “any small builtin type where typical usage needs many instances”?
Why not? What would be the downside of all such built-in types using freelists? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Then why don’t we just register all built-in objects to the freelist? I think our primary focus is on keeping maintenance costs low. Once we add complex to the freelist, we’ll need to maintain it anyway. We already have over 20 object types registered. If we’re going to add more, shouldn’t we also consider a more manageable way to maintain them? We take a similar approach when deciding not to add a fast path, if the benefit isn’t significant enough, we skip it. From what I’ve observed, most recent optimizations are based on pyperformance results. That said, if you still think we should add this, please go ahead. I just wanted to share my concern about adding it by default. Once an object is added to the freelist, it will usually see some benefit, but we should still weigh that against the maintenance burden. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
We already have an API for that, the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I thought of managing the list of types and generating the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Oh ok, I see. I'm not sure that it's worth it. This list evolves rarely and IMO the maintenance cost is low. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
But pyperformance can't measure any performance changes in the Python core type, complex. Is that a bug or a feature? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
In the past, we observed many optimization enhancements for the binary operation, especially for the int or float types. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
This is possible for complex type as well, but it's another story. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM. The change is short and 1.09x faster on the mysin() micro-benchmark is worth it IMO.
@corona10: You consider that the change is not worth it?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM, Okay, let's consider the possibility of usage in the scientific area.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.