New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ArrayBuilder: replace shared with unique #1155
Conversation
Codecov Report
|
f66aafb
to
6608898
Compare
Just for the record - as of the last commit: a reference C++ test is the same as in #690 (without a snapshot call). It takes |
Wait, what? Replacing I was remembering something much smaller, like a 50% improvement or something like that. |
There were two changes so far: removing temporary objects and moving shared pointers instead of copying them. The Here is the test I used: ak::ArrayBuilder myarray(ak::ArrayBuilderOptions(1024, 2.0));
for (int64_t i = 0; i < 10000000; i++) {
// populate builder with lists
myarray.beginrecord();
myarray.field_check("one");
myarray.boolean(true);
myarray.field_check("two");
myarray.integer(1);
myarray.field_check("three");
myarray.real(1.1);
myarray.endrecord();
myarray.beginrecord();
myarray.field_check("one");
myarray.boolean(false);
myarray.field_check("two");
myarray.integer(2);
myarray.field_check("three");
myarray.real(2.2);
myarray.endrecord();
myarray.beginrecord();
myarray.field_check("one");
myarray.boolean(true);
myarray.field_check("two");
myarray.integer(3);
myarray.field_check("three");
myarray.real(3.3);
myarray.endrecord();
} |
That's jaw-dropping. I knew there was a difference, but if I had known it was such a big difference, we would have done this much earlier. Fortunately, though, there will be a version 1.7.0 out soon that we can use as a baseline for studies. If that was the bottleneck (and it's so large that it must be), then my specialized JSON thing (#1165) is probably unnecessary—discovering the type dynamically will probably be as fast as knowing the type ahead of time (because I wrongly thought that it was the type-querying that was slowing it down, rather than the For reasons of keeping things module, the ForthOutputBuffer doesn't use ArrayBuilder's GrowableBuffer. It has its own and the resize update is here: The LayoutBuilder, AwkwardForth, and SpecializedJSON won't see speedups until ForthOutputBuffer is updated in the same way as GrowableBuffer. Actually, in this PR's diff, I don't see any changes to GrowableBuffer's |
I think, it a bit premature to draw conclusions. The next commit drops shared pointer copies for the |
@jpivarski - it looks like the failure is unrelated to this PR - the test fails in a clean area: ======================================================================== FAILURES ========================================================================
_________________________________________________________________ test_numpyarray_grad_3 _________________________________________________________________
def test_numpyarray_grad_3():
def func_numpyarray_3(x):
return x[::-1]
value_jvp, jvp_grad = jax.jvp(
func_numpyarray_3, (test_numpyarray_jax,), (test_numpyarray_tangent_jax,)
)
jit_value = jax.jit(func_numpyarray_3)(test_numpyarray)
value_vjp, vjp_func = jax.vjp(func_numpyarray_3, test_numpyarray_jax)
> assert ak.to_list(value_jvp) == [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
tests/test_0793-jax-element-wise-ops.py:73:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
awkward/operations/convert.py:1020: in to_list
return [to_list(x) for x in array]
awkward/operations/convert.py:1020: in <listcomp>
return [to_list(x) for x in array]
awkward/operations/convert.py:1020: in to_list
return [to_list(x) for x in array]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = DeviceArray(9., dtype=float64)
def __iter__(self):
if self.ndim == 0:
> raise TypeError("iteration over a 0-d array") # same as numpy error
E TypeError: iteration over a 0-d array
../../../anaconda3/lib/python3.8/site-packages/jax/_src/device_array.py:245: TypeError
============================================================== 1 failed, 17 passed in 4.05s ==============================================================
|
Yes, I think something happened in a new JAX version. @ctrl-stormy will be replacing the JAX implementation next spring—it will be based on a different strategy (bottom-up, rather than top-down)—so I think we can disable these tests. I've already done that in #1183, though I didn't get it cleanly in any one commit. If you add pytestmark = pytest.mark.skip(
reason="Top-down JAX tests disabled; to be replaced by bottom-up."
) to tests/test_0645-from-jax.py, tests/test_0645-jax-refcount.py, tests/test_0645-to-jax.py, and tests/test_0793-jax-element-wise-ops.py, immediately after the imports and before the I don't know if these tests will be reinstated as-is when the JAX bottom-up implementation is done or if that implementation will have different tests, but this will at least turn them off for now without losing memory that they're a to-do item. Before releasing Awkward 2.0, we'll sweep through all the skipped tests, reinstating as many as we can, and we'll be reminded of this one at that time. |
As it is now, The test run in a clean area on the left, the same test with this PR on the right. |
Okay, it's significant (factor of 2), but not gigantic (factor of 10). In that case, it's still valuable to write specialized readers for various formats (like #1165: in its sample task, this More importantly, we know why: the atomic increment/decrement ( |
7522a74
to
b39300c
Compare
Hmm... this is strange (MacOS and py310): ================= 1770 passed, 68 skipped, 1 warning in 53.38s =================
Fatal Python error: Segmentation fault
Current thread 0x000000011185edc0 (most recent call first):
Garbage-collecting
<no Python frame>
/Users/runner/work/_temp/3e675f7f-b1be-4603-bf91-708afe92f1cf.sh: line 1: 11033 Segmentation fault: 11 python -m pytest -vv -rs tests
##[error]Bash exited with code '139'.
Finishing: Test |
No description provided.