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

Speed up thermo calculations #89

Merged
merged 4 commits into from
Oct 10, 2024
Merged

Speed up thermo calculations #89

merged 4 commits into from
Oct 10, 2024

Conversation

askprash
Copy link
Member

This was pending for a while, but the gas calculations had loads of unnecessary allocations.

Cleaned these up here by storing the required arrays and passing them to the functions when needed.

Benchmarks on my M2 suggest a pretty massive speed up roughly 4x speed up in the aircraft sizing loop for the default aircraft (really should have done this sooner):

main -

julia> @benchmark TASOPT.engine.gas_N2($100.)
BenchmarkTools.Trial: 10000 samples with 482 evaluations.
 Range (min  max):  222.423 ns    6.751 μs  ┊ GC (min  max):  0.00%  94.45%
 Time  (median):     244.467 ns               ┊ GC (median):     0.00%
 Time  (mean ± σ):   302.899 ns ± 237.818 ns  ┊ GC (mean ± σ):  11.33% ± 12.69%

  █▇▄▁▁▂▄▄▃▁                                                    ▂
  ███████████▇▆▄▄▃▅▁▃▁▃▁▁▁▃▁▁▁▁▁▁▁▃▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▃▅▅▅▅▆▇█▇▇▇▇▇ █
  222 ns        Histogram: log(frequency) by time       1.61 μs <

 Memory estimate: 2.91 KiB, allocs estimate: 6.

julia> @benchmark size_aircraft!($ac; printiter=$false) seconds=30 samples=5
BenchmarkTools.Trial: 5 samples with 1 evaluation.
 Range (min  max):  845.200 ms  900.184 ms  ┊ GC (min  max): 12.34%  12.71%
 Time  (median):     859.258 ms               ┊ GC (median):    12.45%
 Time  (mean ± σ):   863.344 ms ±  22.130 ms  ┊ GC (mean ± σ):  12.65% ±  0.38%

  █ █            █     █                                      █  
  █▁█▁▁▁▁▁▁▁▁▁▁▁▁█▁▁▁▁▁█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█ ▁
  845 ms           Histogram: frequency by time          900 ms <

 Memory estimate: 5.76 GiB, allocs estimate: 14796991.

this PR

julia> @benchmark TASOPT.engine.gas_N2($100.)
BenchmarkTools.Trial: 10000 samples with 999 evaluations.
 Range (min  max):  13.429 ns  55.765 ns  ┊ GC (min  max): 0.00%  0.00%
 Time  (median):     14.014 ns              ┊ GC (median):    0.00%
 Time  (mean ± σ):   14.540 ns ±  1.772 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

  ▄▃▄█▇▄▂▂▁▁▁▁▁ ▁▁ ▁ ▁▁ ▁▁▁▂▁▁  ▁▁                            ▂
  ████████████████████████████████▆▅▁▄▄▄▃▄▃▄▄▄▁▄▄▄▅▅▄▄▄▃▄▅▁▅▄ █
  13.4 ns      Histogram: log(frequency) by time      22.4 ns <

 Memory estimate: 0 bytes, allocs estimate: 0.

julia> @benchmark size_aircraft!($ac; printiter=$false) seconds=30 samples=5
BenchmarkTools.Trial: 5 samples with 1 evaluation.
 Range (min  max):  191.577 ms  195.717 ms  ┊ GC (min  max): 0.00%  0.78%
 Time  (median):     194.004 ms               ┊ GC (median):    0.79%
 Time  (mean ± σ):   193.918 ms ±   1.492 ms  ┊ GC (mean ± σ):  0.66% ± 0.37%

  █                                 ██    █                   █  
  █▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁██▁▁▁▁█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█ ▁
  192 ms           Histogram: frequency by time          196 ms <

 Memory estimate: 53.72 MiB, allocs estimate: 1071974.

Can likely get a little more if I replace all the gas calculations with IdealGases.jl and close #53

@askprash askprash requested a review from ngomezve October 10, 2024 04:41
Copy link

codecov bot commented Oct 10, 2024

Codecov Report

Attention: Patch coverage is 96.42857% with 2 lines in your changes missing coverage. Please review.

Project coverage is 73.23%. Comparing base (430cfd8) to head (841f37f).
Report is 21 commits behind head on main.

Files with missing lines Patch % Lines
src/engine/gasfun.jl 96.22% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #89      +/-   ##
==========================================
- Coverage   73.41%   73.23%   -0.19%     
==========================================
  Files          77       80       +3     
  Lines       13908    13468     -440     
==========================================
- Hits        10211     9863     -348     
+ Misses       3697     3605      -92     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@ngomezve ngomezve left a comment

Choose a reason for hiding this comment

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

Excellent PR! Looking forward to the speedup

@askprash askprash merged commit 5a5c095 into MIT-LAE:main Oct 10, 2024
5 of 6 checks passed
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.

Replace all gas functions with IdealGases.jl
2 participants