-
Notifications
You must be signed in to change notification settings - Fork 779
Open
Labels
Description
#4799 is not yet released but it works by walking the stack on each on_emit() call which is pretty hot code.
I think using a contextvar (or OTel context) would be significantly faster since loading a traceback is slow and then we have to walk the stack. Rough estimate of perf difference:
$ python -m timeit -s 'import traceback' 'sum(
item.name == "on_emit"
and (
item.filename.endswith("export/__init__.py")
or item.filename.endswith(
r"export\__init__.py"
) # backward slash on windows..
)
for item in traceback.extract_stack()
)'
10000 loops, best of 5: 22.8 usec per loop
$ python -m timeit -s 'import contextvars; c = contextvars.ContextVar("c", default=False)' 'token = c.set("True"); bool(c.get()); c.reset(token)'
2000000 loops, best of 5: 157 nsec per loopMetadata
Metadata
Assignees
Labels
Type
Projects
Status
Todo