Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files
|
ikrommyd
force-pushed
the
perf-improve-index
branch
from
September 12, 2026 23:07
5291d41 to
f09001d
Compare
Contributor
|
The documentation preview is ready to be viewed at https://awkward-array.org/doc/pr/4340/ |
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: -8.2% (27 cases total, showing the four best and the worst). benchmark script"""Benchmark for PR #4340 -- cheapen Index construction and slicing."""
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__}")
SIZES = [(10, 3000), (1_000, 1000), (100_000, 50)]
for n, number in SIZES:
offsets = np.arange(0, 3 * n + 1, 3, dtype=np.int64)
content = np.arange(3 * n, dtype=np.float64)
layout = ak.contents.ListOffsetArray(
ak.index.Index64(offsets), ak.contents.NumpyArray(content)
)
array = ak.Array(layout)
glb = {
"ak": ak,
"np": np,
"offsets": offsets,
"content": content,
"layout": layout,
"array": array,
}
print(f"\n--- {n} sublists of 3 ---")
report(
f"build ListOffsetArray+Array n={n}",
"ak.Array(ak.contents.ListOffsetArray("
"ak.index.Index64(offsets), ak.contents.NumpyArray(content)))",
glb,
number=number,
)
report(f"ak.Array(layout) n={n}", "ak.Array(layout)", glb, number=number)
report(f"array[:] n={n}", "array[:]", glb, number=number)
report(f"array[1:-1] n={n}", "array[1:-1]", glb, number=number)
report(f"array[::2] n={n}", "array[::2]", glb, number=number)
report(f"array.layout.offsets[:] n={n}", "array.layout.offsets[:]", glb, number=number)
report(f"ak.num(array) n={n}", "ak.num(array)", glb, number=number)
report(f"ak.flatten(array) n={n}", "ak.flatten(array)", glb, number=number)
report(f"ak.to_layout(array) n={n}", "ak.to_layout(array)", 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.
A few small things in
Index, which gets constructed everywhere: module-levelnumpyinstead ofNumpy.instance()per call, a dtype to class dict instead of constructing five dtypes to compare against, and__getitem__skipsnormalize_sliceand the_metadatadict when the data is known.