clifford icon indicating copy to clipboard operation
clifford copied to clipboard

Improve performance of multivector arithmetic by avoiding copies

Open eric-wieser opened this issue 4 years ago • 4 comments

Multiplications become roughly 20% faster, and addition 33% faster. There's now a new copy argument to the MultiVector constructor.

Some timings:

Edit: These timings are out of date, and include the effects of #283 which used to be part of this PR. We should retime before merging

After:

In [1]: from clifford import Cl
In [2]: layout, _ = Cl(5)
In [3]: a = layout.randomMV(); b = layout.randomMV()

In [4]: %timeit a * b
The slowest run took 4.76 times longer than the fastest. This could mean that an intermediate result is being cached.
20.4 µs ± 11.3 µs per loop (mean ± std. dev. of 7 runs, 1 loop each)

In [5]: %timeit a * b
8.64 µs ± 341 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)

In [6]: %timeit a * b
9.23 µs ± 606 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)

In [7]: %timeit a + b
3.9 µs ± 250 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)

Before:

In [1]: from clifford import Cl
In [2]: layout, _ = Cl(5)
In [3]: a = layout.randomMV(); b = layout.randomMV()

In [4]: %timeit a * b
The slowest run took 4.37 times longer than the fastest. This could mean that an intermediate result is being cached.
18.6 µs ± 14.2 µs per loop (mean ± std. dev. of 7 runs, 1 loop each)

In [5]: %timeit a * b
11.7 µs ± 759 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)

In [6]: %timeit a * b
11.3 µs ± 660 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)

In [7]: %timeit a + b
6.11 µs ± 871 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)

eric-wieser avatar Mar 12 '20 13:03 eric-wieser

Check out this pull request on  ReviewNB

You'll be able to see Jupyter notebook diff and discuss changes. Powered by ReviewNB.

I'm wondering if actually we should just change the default to copy=False. I haven't yet found an internal call that would break if we did this.

eric-wieser avatar Mar 12 '20 13:03 eric-wieser

This pull request introduces 1 alert and fixes 6 when merging 31ff3173ee700028ea4895ecdeb3a09b1fa8f161 into a5c94317634b048c92fc4f73c738c3c5072c23a2 - view on LGTM.com

new alerts:

  • 1 for Syntax error

fixed alerts:

  • 3 for Variable defined multiple times
  • 2 for Unused import
  • 1 for 'import *' may pollute namespace

lgtm-com[bot] avatar Mar 12 '20 17:03 lgtm-com[bot]

Let's not merge this till we:

  • Decide on #282
  • Re-profile it in isolation

eric-wieser avatar Mar 12 '20 19:03 eric-wieser