stan-dev / stanc3

The Stan transpiler (from Stan to C++ and beyond).
BSD 3-Clause "New" or "Revised" License
140 stars 44 forks source link

Clean and speed up Location.of_string_opt #1310

Closed WardBrian closed 1 year ago

WardBrian commented 1 year ago

Submission Checklist

Release notes

Similar to #1302. This is not quite as big a speed up and it is only really called when you have #included code, but it is still nice.

I originally tried @nhuurre's suggestion of storing positions in the preprocessor rather than re-parsing them from strings, this ended up being too complicated and stateful in my initial attempt.

On a contrived example (a file which contains only an include of the motherHOF.stan file) this decreased the total cost of Location.of_string_opt from 3394 calls taking 160.31M cycles to 3394 calls taking 7.83M cycles.

Copyright and Licensing

By submitting this pull request, the copyright holder is agreeing to license the submitted work under the BSD 3-clause license (https://opensource.org/licenses/BSD-3-Clause)

codecov[bot] commented 1 year ago

Codecov Report

Merging #1310 (f1a2fc5) into master (d639c9b) will increase coverage by 0.01%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #1310      +/-   ##
==========================================
+ Coverage   89.01%   89.02%   +0.01%     
==========================================
  Files          64       64              
  Lines        9777     9779       +2     
==========================================
+ Hits         8703     8706       +3     
+ Misses       1074     1073       -1     
Impacted Files Coverage Δ
src/middle/Location_span.ml 92.85% <ø> (-0.48%) :arrow_down:
src/frontend/Environment.ml 66.03% <100.00%> (-1.24%) :arrow_down:
src/frontend/Preprocessor.ml 95.91% <100.00%> (-0.17%) :arrow_down:
src/middle/Location.ml 97.64% <100.00%> (+1.49%) :arrow_up: