Skip to content

31 replace underlying option value datastructure #33

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

Merged
merged 5 commits into from
Oct 14, 2024

Conversation

rsore
Copy link
Owner

@rsore rsore commented Oct 14, 2024

Description

In this development branch I have implemented the proposed changes in #31, replacing the underlying datastructure of ValueContainer with a much more memory-efficient solution, without sacrificing safety or run-time performance.

Essentially the change moves the type of the underlying datastructure from std::array<std::variant<std::optional<typename Option::ValueType>...>> to std::tuple<std::optional<typename Option::ValueType>...>.
The previous solution of using std::variant did work fine, but the issue was that it forces all elements of the array to be the same size, meaning if most value types of the parser takes up a small amount of bytes, but you have a single larger value type, the size of all of them will be forced to the largest size.

Using std::tuple, we can store the values as their exact parsed type, leading to no memory overhead at all. Since the indices of all options are known at compile-time, setting and retrieving values from the container essentially becomes a direct variable lookup, insanely fast!

An additional improvement, though irrelevant to the real scope of this branch, is that I have refactored part of the array_from_delimited_string function. Specifically, I have updated the part of the code that segments the string and appends the views to the resulting array. Previously this was done through manual logic, and the code was a bit hard to follow. Now I utilize a combination of std::views::split and std::ranges::transform to do both the segmentation and appending in a concise manner.

Finally, due to the usage of modern C++20 features, I have had to update the gcc compiler for the test workflow to use gcc14. gcc13 would likely do, but why not just be more modern, it might potentially catch more errors.

Related Issues

Closes #31.

How Has This Been Tested?

The datastructure itself has been closely observed using the debugger to ensure that the data is layed out as expected before, during and after parsing. Functionally there is no change, so no new tests have been introduced, but all existing tests still pass.

rsore added 3 commits October 14, 2024 15:46
…ple rather than std::array. Removes need for std::variant, much more memory efficient
…ality. Reduced mutability and increased readability.
@rsore rsore added the improvement Improvement to existing feature label Oct 14, 2024
@rsore rsore linked an issue Oct 14, 2024 that may be closed by this pull request
Copy link

clang-tidy review says "All clean, LGTM! 👍"

Copy link

clang-tidy review says "All clean, LGTM! 👍"

1 similar comment
Copy link

clang-tidy review says "All clean, LGTM! 👍"

@rsore rsore force-pushed the 31-replace-underlying-option-value-datastructure branch from 41bb964 to 53adc0c Compare October 14, 2024 20:27
Copy link

clang-tidy review says "All clean, LGTM! 👍"

@rsore rsore force-pushed the 31-replace-underlying-option-value-datastructure branch from 53adc0c to e282073 Compare October 14, 2024 20:30
Copy link

clang-tidy review says "All clean, LGTM! 👍"

@rsore rsore force-pushed the 31-replace-underlying-option-value-datastructure branch from e282073 to e64e885 Compare October 14, 2024 20:33
Copy link

clang-tidy review says "All clean, LGTM! 👍"

@rsore rsore merged commit 81a58d5 into main Oct 14, 2024
5 checks passed
@rsore rsore deleted the 31-replace-underlying-option-value-datastructure branch October 14, 2024 20:40
rsore added a commit that referenced this pull request Oct 20, 2024
…datastructure

31 replace underlying option value datastructure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improvement to existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace underlying option value datastructure
1 participant