Opened 8 years ago

Closed 8 years ago

#4960 enhancement closed fixed (fixed)

Speed up twisted.python.context by copying less data

Reported by: Jean-Paul Calderone Owned by: Jean-Paul Calderone
Priority: normal Milestone:
Component: core Keywords:
Cc: Branch: branches/faster-callwithcontext-4960
branch-diff, diff-cov, branch-cov, buildbot
Author: exarkun, fijal


ContextTracker.callWithContext makes a copy of the current context and update it with the new context data. This makes callWithContext somewhat expensive, even if no code actually loads anything from the context.

Contrariwise, it makes it easy to retrieve keys from the context, which most code doesn't bother to do.

We should reverse these, making callWithContext as cheap as we can, even at the cost of slowing down getContext somewhat.

Change History (6)

comment:1 Changed 8 years ago by Jean-Paul Calderone

Author: exarkun
Branch: branches/faster-callwithcontext-4960

(In [31152]) Branching to 'faster-callwithcontext-4960'

comment:2 Changed 8 years ago by Jean-Paul Calderone

(In [31153]) Make the context stack into a chain that you have to follow, instead of a tower with everything piled on top

refs #4960

comment:3 Changed 8 years ago by Jean-Paul Calderone

Author: exarkunexarkun, fijal
Keywords: review added

This doesn't seem to change CPython performance measurably, but it speeds up some benchmarks on PyPy by... maybe... 5% or so (eyeball).

comment:4 Changed 8 years ago by Ying Li

Owner: set to Ying Li
Status: newassigned

comment:5 Changed 8 years ago by Ying Li

Keywords: review removed
Owner: changed from Ying Li to Jean-Paul Calderone
Status: assignednew

build results are good.

The only concern I have is about the performance cost of exceptions, but this concern may not be valid if getContext most often gets the last context appended to the chain. I'm not sure how getContext is usually used.

Otherwise, looks good to merge.

comment:6 Changed 8 years ago by Jean-Paul Calderone

Resolution: fixed
Status: newclosed

(In [31183]) Merge faster-callwithcontext-4960

Author: exarkun, fijal Reviewer: cyli Fixes: #4960

Speed up event dispatch (mostly on PyPy) by reducing the amount of copying involved in the context/logging setup done for each event, at the expense of making key lookup in the context potentially less efficient.

Note: See TracTickets for help on using tickets.