-
Notifications
You must be signed in to change notification settings - Fork 4
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
Some slight speedups of convert units #7
base: main
Are you sure you want to change the base?
Some slight speedups of convert units #7
Conversation
Okay I've applied a memoization approach of pre-computing the standard unit conversions and then looking them up instead of recalculating each time. This results in the same example taking 5.8s on my machine (~22% faster) and convert_units is now down to 800ms aggregate time instead of 2.1s (~61% faster). I'm less familiar with how to distribute R data files, but it does look like storing a table of pre-computed unit conversions will be a significant speedup to the overall package. |
This is a good idea. First step will be to move your hash map creation into the data-raw file and make your hash map an .rda file. Also consider using a named list or dataframe if possible to match other code. |
I've made a few changes:
The end result: Same example improved from 7.4s (original) to 5.4s (-27%) Amount of time being spent in convert_units from 2.1s to .09s (-97.5%) 🥳 🏃 |
Just pushed an update that should fix the checks. Moves the new .rda files to not be exported, only used by the package internally. If you want to run checks locally, devtools::check() runs most of the same things as our R-CMD-check actions - it's a good way to see whether you have anything causing warnings. |
Co-authored-by: Sierra Johnson <[email protected]>
Co-authored-by: Sierra Johnson <[email protected]>
Co-authored-by: Sierra Johnson <[email protected]>
While running the "help_functions_chemdose_ph" vignette I started profiling some of the code as I noticed it was taking a while to run on my computer. Specifically I was profiling this snippet with profvis
The baseline case on main was taking ~7.5 seconds to run on my machine:
![image](https://private-user-images.githubusercontent.com/8097919/382080816-10dc6b1d-e447-46aa-bfd2-540f5856c78a.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5OTQwODEsIm5iZiI6MTczODk5Mzc4MSwicGF0aCI6Ii84MDk3OTE5LzM4MjA4MDgxNi0xMGRjNmIxZC1lNDQ3LTQ2YWEtYmZkMi01NDBmNTg1NmM3OGEucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIwOCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMDhUMDU0OTQxWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MTZmZDAxYjAyYzIzMmVlOWUyZDEzZTY5YWI3N2M5ZWY3NmJhNzJmY2QxNTI5OWEzZjMxZGI0ZDZhMzY4NjU2MSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.75kQn_JNoyA21EYBQimG0Mn0BL793UiV2UDyrzmw9qk)
With convert_units accounting for ~2.1 seconds of runtime. Although results are very messy.
After these optimizations the example is down to ~7.0 seconds, and convert_units is down to 1.9 seconds. Not huge gains, but a start.
![image](https://private-user-images.githubusercontent.com/8097919/382081207-41a4de1a-e68e-45ec-ac45-533cfb489ce2.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5OTQwODEsIm5iZiI6MTczODk5Mzc4MSwicGF0aCI6Ii84MDk3OTE5LzM4MjA4MTIwNy00MWE0ZGUxYS1lNjhlLTQ1ZWMtYWM0NS01MzNjZmI0ODljZTIucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIwOCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMDhUMDU0OTQxWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZmI4ZWRjYWQyZDM0ZWYxNWM1YmVhYjU5M2FlNTEwMjZmYjkyMjk2ZjI0ZjRmZmM2Mjk0YTA2OTVjNTVjOTI1MiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.hB9JxLPKsAqOSnNSXFTYeTuAZByaFxvXVidC9nc7y1k)
Going to continue to optimize from here, but wanted to at least show these gains were possible.