-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Make derivative 5-8 times faster #3322
base: develop
Are you sure you want to change the base?
Conversation
Wow, this is a huge performance improvement! That is a smart idea, thanks Paul. Your PR looks good to go. I have only one thought: the old solution with |
@josdejong Good question! When Things could behave differently if
Old code would depend on whether constructed node appears anywhere in the input as a sub-expression. New code will always take derivative of it. |
Bulletproof way would be to add memoization to |
@josdejong PTAL Will post a new benchmark shortly, can't promise it will be as good as the previous one though. |
I've updated the benchmark and it made measurement error smaller (or whatever that Adding Let me know if you have any suggestions how to improve this PR. Numbers for the new benchmark:
|
derivative seems to spend most of its time inside _toString, because
constNodes[foo]
converts keys to strings.I'm not sure Set is really needed as a separate type, but because
_derivative
is atyped
function I had to introduce it.Benchmark before the change (Core i5 2017 macbook):
ddf x 23.77 ops/sec ±0.54% (43 runs sampled)
df x 79.58 ops/sec ±0.57% (69 runs sampled)
ddf x 23.62 ops/sec ±0.54% (43 runs sampled)
df x 78.86 ops/sec ±0.50% (74 runs sampled)
ddf x 23.73 ops/sec ±0.47% (43 runs sampled)
df x 79.73 ops/sec ±0.57% (69 runs sampled)
ddf x 23.85 ops/sec ±0.64% (44 runs sampled)
df x 80.17 ops/sec ±0.43% (69 runs sampled)
Benchmark with this PR (same old macbook):
ddf x 1,781 ops/sec ±14.63% (80 runs sampled)
df x 5,161 ops/sec ±30.53% (62 runs sampled)
ddf x 1,769 ops/sec ±17.68% (79 runs sampled)
df x 5,286 ops/sec ±30.00% (72 runs sampled)
ddf x 1,910 ops/sec ±4.58% (85 runs sampled)
df x 4,275 ops/sec ±41.16% (58 runs sampled)
ddf x 1,959 ops/sec ±4.91% (88 runs sampled)
df x 4,474 ops/sec ±37.39% (62 runs sampled)