Opened 4 years ago

Closed 4 years ago

#4960 enhancement closed fixed (fixed)

Speed up twisted.python.context by copying less data

Reported by: exarkun Owned by: exarkun
Priority: normal Milestone:
Component: core Keywords:
Cc: Branch: branches/faster-callwithcontext-4960
(diff, github, buildbot, log)
Author: exarkun, fijal Launchpad Bug:

Description

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 4 years ago by exarkun

  • Author set to exarkun
  • Branch set to branches/faster-callwithcontext-4960

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

comment:2 Changed 4 years ago by exarkun

(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 4 years ago by exarkun

  • Author changed from exarkun to exarkun, 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 4 years ago by cyli

  • Owner set to cyli
  • Status changed from new to assigned

comment:5 Changed 4 years ago by cyli

  • Keywords review removed
  • Owner changed from cyli to exarkun
  • Status changed from assigned to new

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 4 years ago by exarkun

  • Resolution set to fixed
  • Status changed from new to closed

(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.