Conversation
|
ikrommyd
marked this pull request as ready for review
September 13, 2026 10:33
Member
Author
|
🤖 AI text below 🤖 CPU timings,
Median across all cases: -3.8% (28 cases total, showing the four best and the worst). benchmark script# Benchmark for PR #4341: caching backend/nplike lookups for unrecognised types.
# Every statement below mixes plain Python objects (int/float/list/str) into
# awkward operations, so the "type nothing recognises" lookup path is hit often.
import statistics, timeit
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__}")
def make(n):
return ak.Array([[1.1, 2.2, None], [], [3.3]] * n)
CASES = [
("add python int", "array + 1"),
("add python float", "array + 1.5"),
("multiply python int", "array * 2"),
("compare python float", "array > 2.0"),
("fill_none python int", "ak.fill_none(array, 0)"),
("fill_none python str", "ak.fill_none(array, 'x')"),
("getitem python int", "array[0]"),
("getitem python slice", "array[1:]"),
("getitem nested python ints", "array[0, 0]"),
("getitem python list", "array[[0, 1, 2]]"),
("with_field python scalar", "ak.zip({'x': array, 'y': array}) "),
("concatenate with python list", "ak.concatenate([array, [[9.9]]])"),
("where python scalars", "ak.where(array > 2.0, 1.0, 0.0)"),
("to_list roundtrip", "ak.Array(pylist)"),
]
for n in (1, 3000):
array = make(n)
pylist = array.to_list()
glb = {"ak": ak, "array": array, "pylist": pylist}
number = 1000 if n == 1 else 50
print(f"\n--- {len(array)} entries ---")
for label, stmt in CASES:
report(f"{label} [n={len(array)}]", stmt, glb, number=number) |
Contributor
|
The documentation preview is ready to be viewed at https://awkward-array.org/doc/pr/4341/ |
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.
backend_of_objandnplike_of_objre-scanned every registered lookup factory on every call for types that are not arrays at all, for example the field name string passed toSlicingErrorContext. We cache the misses too and clear them when a new backend or nplike is registered.