Skip to content

bpo-37358: Use vectorcall for functools.partial#14284

Merged
miss-islington merged 2 commits into
python:masterfrom
jdemeyer:partial_vectorcall
Jul 13, 2019
Merged

bpo-37358: Use vectorcall for functools.partial#14284
miss-islington merged 2 commits into
python:masterfrom
jdemeyer:partial_vectorcall

Conversation

@jdemeyer

@jdemeyer jdemeyer commented Jun 21, 2019

Copy link
Copy Markdown
Contributor

@jdemeyer
jdemeyer force-pushed the partial_vectorcall branch from 3c19903 to fc44c0e Compare June 24, 2019 09:21
@codecov

codecov Bot commented Jun 24, 2019

Copy link
Copy Markdown

Codecov Report

Merging #14284 into master will decrease coverage by <.01%.
The diff coverage is 86.53%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #14284      +/-   ##
==========================================
- Coverage   82.75%   82.75%   -0.01%     
==========================================
  Files        1840     1840              
  Lines      560791   560780      -11     
  Branches    41431    41431              
==========================================
- Hits       464110   464099      -11     
- Misses      87598    87602       +4     
+ Partials     9083     9079       -4
Impacted Files Coverage Δ
Modules/_functoolsmodule.c 83.24% <86.53%> (+0.38%) ⬆️
Lib/test/test_audit.py 81.81% <0%> (-0.8%) ⬇️
Lib/test/test_dictcomps.py 95.65% <0%> (-0.78%) ⬇️
Lib/enum.py 75.21% <0%> (-0.22%) ⬇️
Lib/asyncio/base_events.py 83.41% <0%> (-0.2%) ⬇️
Lib/test/test_gdb.py 4.34% <0%> (-0.09%) ⬇️
Lib/test/test_named_expressions.py 95.92% <0%> (-0.06%) ⬇️
Lib/test/test_importlib/test_abc.py 97.65% <0%> (-0.05%) ⬇️
Python/sysmodule.c 74.26% <0%> (-0.03%) ⬇️
Objects/unicodeobject.c 79.59% <0%> (-0.01%) ⬇️
... and 10 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 770847a...fc44c0e. Read the comment docs.

@encukou

encukou commented Jul 5, 2019

Copy link
Copy Markdown
Member

Is partial_vectorcall_no_args useful? It kicks in only if no arguments (positional nor keyword) are added at all. Are such no-op partial objects worth optimizing?

@jdemeyer

jdemeyer commented Jul 5, 2019

Copy link
Copy Markdown
Contributor Author

Are such no-op partial objects worth optimizing?

To be honest, I have no idea. I just noticed that this could be optimized, so I did it. The behaviour of partial(func) would be just like staticmethod(func) but callable itself.

Do you want me to remove that special case?

@encukou

encukou commented Jul 5, 2019

Copy link
Copy Markdown
Member

To be honest, I have no idea. I just notices that this could be optimized, so I did it.

That sounds like premature optimization.
I wonder how much this PR itself helps; did you run any benchmarks?

The behaviour of partial(func) would be just like staticmethod(func) but callable itself.

If that is an actual use case for that, just make staticmethod callable. AFAIK, in the discussions around that ⁽⁰⁾ ⁽¹⁾, the only arguments against were not enough actual use cases.
We shouldn't optimize for people repurposing partial for this.

Do you want me to remove that special case?

Yes, unless there is a need for the complication.

@jdemeyer

jdemeyer commented Jul 8, 2019

Copy link
Copy Markdown
Contributor Author

I tried 3 simple micro-benchmarks (without PGO):

  1. f = partial(len) and then benchmarking f(())
    before: Mean +- std dev: 70.3 ns +- 0.2 ns
    after: Mean +- std dev: 47.3 ns +- 0.1 ns
  2. f = partial(len, []) and then benchmarking f()
    before: Mean +- std dev: 50.2 ns +- 0.2 ns
    after: Mean +- std dev: 36.1 ns +- 0.3 ns
  3. f = partial(list.count, []) and then benchmarking f(0)
    before: Mean +- std dev: 84.4 ns +- 1.3 ns
    after: Mean +- std dev: 47.9 ns +- 2.2 ns

So there is a clear performance improvement in all cases.

@jdemeyer

jdemeyer commented Jul 8, 2019

Copy link
Copy Markdown
Contributor Author

Failed Travis CI build is due to OSError: [Errno 113] No route to host clearly not caused by this PR.

@encukou

encukou commented Jul 13, 2019

Copy link
Copy Markdown
Member

Looks good! Thank you!

@miss-islington

Copy link
Copy Markdown
Contributor

@jdemeyer: Status check is done, and it's a success ✅ .

@miss-islington
miss-islington merged commit ed184c0 into python:master Jul 13, 2019
@jdemeyer
jdemeyer deleted the partial_vectorcall branch July 14, 2019 09:57
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.

5 participants