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

Refactor get_available_variable_names to return a span<string> rather than a concrete vector<string> #644

Merged

Conversation

PhilMiller
Copy link
Contributor

@PhilMiller PhilMiller commented Sep 20, 2023

This allows implementations to vary how they store and provide the available names (to some extent), potentially cutting memory overhead.

Changes

  • Change DataProvider interface and all implementations to return span<string>
  • Use auto at call sites, since they uniformly don't actually care that they've gotten a vector, as opposed to a find()-able collection

Notes

Checklist

  • PR has an informative and human-readable title
  • Changes are limited to a single goal (no scope creep)
  • Code can be automatically merged (no conflicts)
  • Code follows project standards (link if applicable)
  • Passes all existing automated tests
  • Any change in functionality is tested
  • New functions are documented (with a description, list of inputs, and expected output)
  • Placeholder code is flagged / future todos are captured in comments
  • Project documentation has been updated (including the "Unreleased" section of the CHANGELOG)
  • Reviewers requested with the Reviewers tool ➡️

@PhilMiller PhilMiller force-pushed the forcings-span-available-variables branch from b044126 to c157e50 Compare September 20, 2023 13:36
@PhilMiller PhilMiller marked this pull request as draft September 20, 2023 13:37
@PhilMiller PhilMiller force-pushed the forcings-span-available-variables branch from c157e50 to bd174bc Compare September 20, 2023 13:40
@PhilMiller PhilMiller marked this pull request as ready for review September 20, 2023 13:56
@PhilMiller
Copy link
Contributor Author

PhilMiller commented Sep 20, 2023

The broader philosophical goal of this change and others like it is to make it so that wherever possible, the code deals in terms of cheap to create/copy/manipulate value types such as span, rather than types that require careful consideration of how to handle them at every place in the code that they're used. In particular, having a vector-based return type invites mistakes of accidentally picking it up by value and copying it, along with all its contents.

program--
program-- previously approved these changes Sep 20, 2023
@PhilMiller PhilMiller force-pushed the forcings-span-available-variables branch from 6ed43ed to f3cb2f0 Compare September 21, 2023 16:18
@PhilMiller
Copy link
Contributor Author

With the merge of #601, this has been expanded to spare the memory footprint cost of an empty vector for every instance of NullForcingProvider int he realization configuration.

@mattw-nws mattw-nws merged commit d2bc3b2 into NOAA-OWP:master Sep 21, 2023
18 of 19 checks passed
@PhilMiller PhilMiller deleted the forcings-span-available-variables branch September 21, 2023 16:59
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.

3 participants