Skip to content

Resolves Issue 4810, cumSum and cumProd performance - #4819

Merged
ajpotts merged 1 commit into
Bears-R-Us:mainfrom
drculhane:ForIssue4810
Oct 2, 2025
Merged

ajpotts merged 1 commit into
Bears-R-Us:mainfrom
drculhane:ForIssue4810

Conversation

@drculhane

@drculhane drculhane commented Aug 25, 2025 •

Copy link
Copy Markdown
Contributor

Closes #4810

Update to update:

Based on Engin's recent feedback, this should now be ready for review. The final changes are very simple. In the 1D case, it reverts to the original code. The rest of the comments below are now out of date.


Update: I added plotting to the performance tool. Enter any value as a 3rd argument and it will plot the measured time for all of the trials. Still not sure this is helpful.

I commented out the console logging because that has more affect on runtime than the calculations do.


Bottom Line Up Front: I'm trying to nail down the performance problem noted in Issue 4810. So far I'm not succeeding. This PR has both old and new versions, and some performance measuring code. (The benchmark doesn't run the old ones, because there are no corresponding numpy names for them.)

The old versions are: ak.oldcumsum and ak.oldcumprod. The new ones are: ak.cumsum and ak.cumprod.

I've attached a python program, pperformance.py, meant to time the old vs. new.

  • python3 pperformance 100 2000 will run 100 trials of a pdarray 2000 elements long, and display mean/std
  • python3 pperformance 100 2000 yes will do all of that, and also show the plot described above.

What do I test? I test all four functions via their python interfaces (ak.oldcumsum, ak.oldcumprod, ak.cumsum, ak.cumprod) and I also do tests that directly invoke the four chapel procs via generic_msg (these runs ignore the output). This meant to reduce the effect of the python interpreter on the timing.

The input data is not random. It's ak.arange(size) + 1. Since it's always the same, the test results should be consistent. They're not. Run it and see. According to this performance tool, the new versions are almost always worse than the old ones, even though the code is virtually identical.

Here's the test program:
pperformance.py

Some background: when I wrote PR 4755, I updated the chapel proc cumSum and cumProd to implement the more complicated functions cumulative_sum and cumulative_prod. These allow multi-dim, axis slicing, and the boolean includeInitial. When the input rank is 1 and the flag is False, cumulative_sum should give the same results as cumsum. Similarly for cumulative_prod and cumprod.

@drculhane
drculhane marked this pull request as draft August 25, 2025 18:02
@drculhane drculhane changed the title Attempting to time the differences Attempting to resolve Issue 4810 Aug 25, 2025

@e-kayrakli e-kayrakli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Andy! And I apologize for the delay. Looking at the diff, it is a good bet that this will improve performance. The parts that you are replacing has two potential performance issues:

  • You create cs and return it after some edits. This will make compiler's job difficult removing an array out of the operation. Whereas just + scan x can have better chance at the compiler avoiding a redundant array copy.
  • Even with includeInitial==false which is the faster option no matter what, cs[0..] = (+ scan x):t; is an assignment into an array slice rather than an array (regardless of the slice being the full array, practically speaking). That will take a different codepath in the modules that can handle more complicated scenarios that slice assignment may bring. Imaginably, that will cost some time. Moreover, that line also has a cast, which should be unnecessary, I think.

In any case chapel-lang/chapel#27828 will put this branch in the performance playground allowing us to collect some data. You can finalize the PR after we know for sure that this will recover performance.

Comment thread src/StatsMsg.chpl Resolved
@e-kayrakli

Copy link
Copy Markdown
Contributor

As for the performance experiments:

pdarray 2000 elements long

This is very tiny to be able to make a judgement on the performance. Your data is 16KB. For example, that's 1/8th of an Apple M1's L1 cache. Even though some of your runs do not go through the Arkouda interface, you are still running a Python interpreter, whose data might be larger than that amount meaning that the performance you'll get will depend entirely on what's in the cache. Another challenge with working with data that can fit in (especially L1 cache) is if you are using your personal machine, OS will do a lot of time-sharing between processes which will share L1. So, your performance stability will be at the mercy of the OS.

I still think there's a good chance your script can detect the difference. Two things to make sure that you can do that:

  • Use large data. Try to go beyond what last-level cache (LLC) can store. Couple hundreds of megs should be the minimum data size.
  • In one run, test only one function. If you run oldcumsum first, it will warm up your cache and all the lookahead mechanisms in the hardware for your data. Then if you run oldcumprod, things will be warmed up, potentially benefitting the subsequent calls. You doing 100 trials could mitigate that effect, but I would be more comfortable running different versions in more isolated way.

In any case, though, I don't think you have to do any of that. Hopefully, starting tomorrow, we'll get good results on the playground and you can just work with that.

e-kayrakli added a commit to chapel-lang/chapel that referenced this pull request Sep 18, 2025
This PR puts Bears-R-Us/arkouda#4819 in the
Arkouda perf playground. We expect [Scan
regressions](Bears-R-Us/arkouda#4810) to
recover.

[Trivial, not reviewed]
@drculhane
drculhane force-pushed the ForIssue4810 branch 3 times, most recently from e91a6cc to f6a7bc5 Compare September 29, 2025 13:51
@drculhane drculhane changed the title Attempting to resolve Issue 4810 Resolves Issue 4810, cumSum and cumProd performance Sep 29, 2025
@drculhane
drculhane marked this pull request as ready for review September 30, 2025 11:39

@1RyanK 1RyanK left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@jaketrookman jaketrookman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@ajpotts
ajpotts added this pull request to the merge queue Oct 2, 2025
Merged via the queue into Bears-R-Us:main with commit 79eb121 Oct 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cumsum and cumprod performance regression

5 participants