[REFACTOR] Avoid computing samples eagerly in SimulationResults#423
[REFACTOR] Avoid computing samples eagerly in SimulationResults#423mattdailis merged 3 commits intodevelopfrom
Conversation
Mythicaeda
left a comment
There was a problem hiding this comment.
Looks fine, although seeing it appear in the mission models makes me wonder how often this calculation will be called per SimulationResults object. Would it be worth it to instead make resourceSamples a private field that is not assigned at construction, and have it accessed through a getter that assigns the output of takeSamples into it if resourceSamples is null? Then we only run takeSamples at most once per SimulationResults object.
If we expected this computation to happen multiple times, absolutely, I think caching it in a field would be a valid approach. 💯 As it stands, we've moved away from this method (it provides strictly less information than |
b2d78d9 to
84fe058
Compare
So this refactor is setup for an eventual deprecation? If so, then I think I'm fine with making it the responsibility of whoever calls the public method to cache its return value. |
When I brought up the possibility of deprecation, @patkenneally explained that we should keep the capability in case API clients want it, but that we should encourage people to use the continuous profiles directly. So - yes, it's "discouraged" if not exactly "deprecated for removal". |
|
Personally, I'd like to see the |
b389108 to
a620523
Compare
Done 👍 The sampling logic is now the responsibility of the |
a620523 to
19f1b68
Compare
|
Awesome! Thanks for doing that! |
There are now two separate flows - when a simulation is run, and when samples are requested explicitly. Samples are not written to the database, so there is no need to compute samples unless they are requested.
…tsAction::getResourceSamples
19f1b68 to
d924e07
Compare
This plan.json is used in the main method in SimulateMapSchedule - it's not used for any automated tests, but it can be used for manual testing. In #334, we added a z parameter to the FooActivity, but forgot to update this file.
d924e07 to
2aaa270
Compare
Description
This PR removes
resourceSamplesas a field onSimulationResults. Prior to this PR, this field was derived fromrealProfilesanddiscreteProfilesvia thetakeSamplesmethod - upon calling theSimulationResultsconstructor,takeSampleswould be called eagerly.In typical usage,
resourceSamplesis unused - the simulation results are written to the database using therealProfilesanddiscreteProfilesdirectly. The only time it is used (outside of testing) is via the explicitresourceSampleshasura action.This PR moves computation of resource samples out of the
SimulationResultsconstructor, so that they can be computed when requested, but not by default.I have not done any performance measurements to see whether or not this change is significant - nevertheless, I believe avoiding needless computations is generally a good thing.
Verification
I spun up a local Aerie deployment and checked that running simulations and viewing their results worked, and I also called the
resourceSamplesendpoint directly.Documentation
No functional behavior has changed, so no documentation needs to be updated.
Future work
No future work