Repository navigation
Conversation
ikrommyd
marked this pull request as ready for review
September 13, 2026 10:33
ikrommyd
marked this pull request as draft
September 13, 2026 11:32
ikrommyd
marked this pull request as ready for review
September 13, 2026 13:27
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files
|
Member
Author
|
🤖 AI text below 🤖 CPU timings,
Median across all cases: -0.4% (15 cases total, showing the four best and the worst). benchmark script"""Benchmark for PR #4338: cached kernel lookup + void-pointer ctypes calls.
The win is per-kernel-call overhead, so most cases are many operations on
*small* arrays; the last case is large so that the kernel body dominates and
shows there is no regression there.
"""
from __future__ import annotations
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__}")
rng = np.random.default_rng(12345)
small = ak.Array([[1, 2, 3], [], [4, 5], [6], [7, 8, 9, 10]])
small_rec = ak.Array([{"x": [1, 2], "y": 1.5}, {"x": [], "y": 2.5}, {"x": [3], "y": 3.5}])
small_opt = ak.Array([[1, None, 3], [], [None], [4, 5]])
counts = rng.integers(0, 8, size=1_000_000)
big = ak.unflatten(ak.Array(rng.random(int(counts.sum()))), counts)
glb = globals()
# --- small arrays: dispatch overhead dominates ---------------------------------
report("ak.num(small)", "ak.num(small)", glb, number=2000)
report("ak.flatten(small)", "ak.flatten(small)", glb, number=2000)
report("small[:, 1:]", "small[:, 1:]", glb, number=2000)
report("small[[0, 2, 4]]", "small[[0, 2, 4]]", glb, number=2000)
report("small[small_mask]", "small[np.array([True, False] * 2 + [True])]", glb, number=2000)
report("ak.to_list(small)", "ak.to_list(small)", glb, number=1000)
report("ak.is_none(small_opt, axis=1)", "ak.is_none(small_opt, axis=1)", glb, number=1000)
report("ak.drop_none(small_opt)", "ak.drop_none(small_opt)", glb, number=500)
report("ak.sum(small, axis=1)", "ak.sum(small, axis=1)", glb, number=1000)
report("ak.cartesian([small, small], axis=1)", "ak.cartesian([small, small], axis=1)", glb, number=200)
report("small_rec.x", "small_rec.x", glb, number=5000)
report("ak.concatenate([small, small])", "ak.concatenate([small, small])", glb, number=500)
# --- large array: kernel body dominates, check for no regression ---------------
report("ak.num(big) [1M lists]", "ak.num(big)", glb, number=20)
report("ak.flatten(big) [1M lists]", "ak.flatten(big)", glb, number=20)
report("ak.sum(big, axis=1) [1M lists]", "ak.sum(big, axis=1)", glb, number=10) |
Contributor
|
The documentation preview is ready to be viewed at https://awkward-array.org/doc/pr/4338/ |
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.
Kernels were constructed anew on every dispatch, so they are cached on the backend now. Building a typed ctypes pointer for each buffer also costs several times more than the kernel call itself, so the same function is re-prototyped with
void *parameters and handed plain addresses instead.The numpy and jax kernels call the same awkward-cpp functions (which is why the jax backend needs its buffers on the cpu), so they now share that calling convention in a common base and differ only in how a buffer's address is taken. The cache sits in
Backend.__getitem__with each backend providing_new_kernel, so cupy and typetracer get it as well. It matters most for jax, whose kernel constructor was importing jax and parsing a version string on every lookup.Kernel lookup goes from 143 ns to 44 ns, and a small kernel call from 9.2 us to 5.2 us.