Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files
|
Contributor
|
The documentation preview is ready to be viewed at https://awkward-array.org/doc/pr/4331/ |
Member
Author
|
I need to think about this a little more but this has been discussed as a problem in the past where the error context is built anyways for no reason. Keeping it in draft for a bit |
ikrommyd
marked this pull request as ready for review
September 13, 2026 14:10
Member
Author
|
🤖 AI text below 🤖 CPU timings,
Median across all cases: -2.2% (12 cases total, showing the four best and the worst). benchmark script"""Benchmark for PR #4331: build error-context strings only when decorating.
Every `ak.*` operation enters an OperationErrorContext and every `__getitem__`
enters a SlicingErrorContext, so the cost measured here is the per-call
book-keeping those context managers add to ordinary, non-raising user code.
"""
import statistics
import timeit
import numpy as np
import awkward as ak
def report(label, stmt, glb, *, number, repeats=7):
ts = timeit.repeat(stmt, number=number, repeat=repeats, globals=glb)
us = sorted(t / number * 1e6 for t in ts)
print(
f"{label:<45} {statistics.median(us):10.3f} us min {us[0]:10.3f} sd {statistics.stdev(us):8.3f} (n={number}x{repeats})"
)
print(f"awkward {ak.__version__} from {ak.__file__}")
# 6 statements x 2 sizes = 12 benchmarks.
STATEMENTS = [
"ak.num(a, axis=1)", # one array arg + one kwarg
"ak.sum(a, axis=1)",
"ak.zip({'x': a, 'y': a})", # dict arg (no backend of its own)
"ak.concatenate([a, a])", # list arg -> recursive backend probe
"a[1:-1]", # SlicingErrorContext, plain slice
"a[idx]", # SlicingErrorContext, array slice
]
for size, tag, number in ((10, "small", 20_000), (1_000_000, "large", 100)):
flat = np.arange(3 * size, dtype=np.int64)
array = ak.unflatten(flat, np.full(size, 3, dtype=np.int64))
index = np.arange(1, size, dtype=np.int64)
glb = {"ak": ak, "a": array, "idx": index}
for statement in STATEMENTS:
report(f"{statement} [{tag} n={size}]", statement, glb, number=number) |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Every public call builds an
ErrorContextso that an exception raised inside it can be decorated with the call and its arguments, but the exception almost never happens. The contexts now keep their arguments and format them only when the note is actually read, which also makesPartialFunctionandWeakMethodProxyunnecessary: they existed to defer the formatting while keeping the context weakly referenced, and with the arguments held directly there is no cycle to avoid.The one case that still formats eagerly is a delayed (cuda) backend, because its errors surface later at synchronization from a context that is kept alive until then, and that context must not pin its arguments in the meantime. Those contexts drop the arguments as soon as they have the strings.
Exception types, messages and notes are unchanged; I diffed them against main over the error paths I could think of (bad field, bad axis, jagged slice mismatch, ufunc broadcast failures, nested operations and slices, typetracer, threads, and cuda errors surfaced through
synchronize_cuda).Saves roughly a microsecond per call, which is 4-10% on cheap operations like
ak.numorarr[0].