Skip to content
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

Optimize __lookup function #24

Closed
chrispcampbell opened this issue Jul 10, 2020 · 2 comments · Fixed by #27
Closed

Optimize __lookup function #24

chrispcampbell opened this issue Jul 10, 2020 · 2 comments · Fixed by #27
Assignees
Milestone

Comments

@chrispcampbell
Copy link
Contributor

chrispcampbell commented Jul 10, 2020

The __lookup function is called thousands of times (167548 times, to be exact) when running the En-ROADS model, so some simple optimizations will help improve performance.

I was able to get some decent wins just by reducing the number of instructions in the inner loop. Using binary search could potentially help a bit, but my initial experiment with that didn't provide much improvement over a straight linear search. About half of the lookup tables in En-ROADS are 100-200 elements, while the other half have only 10-50 elements, so linear search is probably sufficient.

@chrispcampbell chrispcampbell self-assigned this Jul 10, 2020
@chrispcampbell
Copy link
Contributor Author

Here are some performance numbers for this change relative to other recent optimizations.

Performance

MacBook Pro (2019) | 2.4 GHz 8-core i9, 32 GB RAM, macOS 10.15

Issue C run (ms) Wasm run (ms) Wasm init (ms) JS mem (MB) Page mem (MB)
baseline 45.8 87.5 38.0 94 685
SDE 18 46.0 85.6 18.0 39 672
SDE 19 42.8 49.4 15.0 38 25
SDE 22 34.8 44.8 15.0 38 21
SDE 23 32.7 42.8 13.0 38 32
SDE 24 26.6 38.2 13.0 39 26

iPhone 8 | A11, iOS 13

Issue C run (ms) Wasm run (ms) Wasm init (ms) JS mem (MB) Page mem (MB)
baseline 39.9 187.0 165.0 39 645
SDE 18 40.3 219.0 86.0 38 724
SDE 19 40.1 81.6 83.0 38 41
SDE 22 35.5 74.6 86.0 40 40
SDE 23 31.1 73.6 82.0 41 39
SDE 24 28.5 71.6 82.0 40 38

iPad Air (2013) | A7, iOS 12

Issue C run (ms) Wasm run (ms) Wasm init (ms) JS mem (MB) Page mem (MB)
baseline 151.0 1372.2 30146.0 77 331
SDE 18 166.0 1408.0 4416.0 42 395
SDE 19 151.0 837.6 1291.0 45 41
SDE 22 137.0 771.6 1484.0 44 40
SDE 23 110.1 642.2 1148.0 44 41
SDE 24 111.8 638.4 1236.0 45 37

Size

Issue Wasm size (bytes)
baseline 1,084,036
SDE 18 773,968
SDE 19 776,851
SDE 22 737,028
SDE 23 741,668
SDE 24 741,677

Legend

Issue Date Notes
baseline 2020/07/08 baseline prior to performance work
SDE 18 2020/07/09 change lookup init to use static arrays
SDE 19 2020/07/09 break large functions into chunked subfunctions
SDE 22 2020/07/10 replace wrapper functions with macros
SDE 23 2020/07/10 replace dimension array access with simple index
SDE 24 2020/07/10 optimize __lookup function

@chrispcampbell
Copy link
Contributor Author

Merged to develop in 6ce8d49.

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 a pull request may close this issue.

1 participant