Ticket #4960 enhancement closed fixed

Opened 2 years ago

Last modified 2 years ago

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

1

Changed 2 years ago by exarkun

  • branch set to branches/faster-callwithcontext-4960
  • branch_author set to exarkun

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

2

Changed 2 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

3

Changed 2 years ago by exarkun

  • keywords review added
  • branch_author changed from exarkun to exarkun, fijal

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

4

Changed 2 years ago by cyli

  • owner set to cyli
  • status changed from new to assigned

5

Changed 2 years ago by cyli

  • owner changed from cyli to exarkun
  • status changed from assigned to new
  • keywords review removed

 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.

6

Changed 2 years ago by exarkun

  • status changed from new to closed
  • resolution set to fixed

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