Skip to content

Reduce string copies in parse #394

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 20 commits into from
Sep 20, 2024
Merged

Reduce string copies in parse #394

merged 20 commits into from
Sep 20, 2024

Conversation

fktn-k
Copy link
Owner

@fktn-k fktn-k commented Sep 19, 2024

This PR has significantly reduced the number & size of string copies and subsequent heap allocations during parsing of YAML sources by the following major changes:

  • use fkyaml::detail::str_view class which is newly implemented as a minimal implementation of std::string_view (since C++17) even when the library is built with C++11 or C++14 so that inspections into YAML sources are executed more effectively
  • avoid copying YAML sources into a std::string object if they don't contain CR newline codes and are an array/container which has contiguous byte array to store actual characters (like char [N], std::vector or std::string)
  • reduced unnecessary std::string instanciations during the parsing

As a result of the above changes, the benchmark scores of this library has increased by 0.5MiB/s (when parsing tool/benchmark/macos.yml file with the same environment described in README.md):

last benchmark score benchmark score after the changes
40.491 MiB/s 41.051 MiB/s

Pull Request Checklist

Read the CONTRIBUTING.md file for detailed information.

  • Changes are described in the pull request or in a referenced issue.
  • The test suite compiles and runs without any error.
  • The code coverage on your branch is 100%.
  • The documentation is updated if you added/changed a feature.

Please don't

  • The C++11 support varies between different compilers and versions. Please note the list of supported compilers. Some compilers like GCC 4.7 (and earlier), Clang 3.3 (and earlier), or Microsoft Visual Studio 13.0 and earlier are known not to work due to missing or incomplete C++11 support. Please refrain from proposing changes that work around these compiler's limitations with #ifdefs or other means.
  • Please refrain from proposing changes that would break YAML specifications. If you propose a conformant extension of YAML to be supported by the library, please motivate this extension.
  • Please do not open pull requests that address multiple issues.

@fktn-k fktn-k self-assigned this Sep 19, 2024
@fktn-k fktn-k added the improvement refactoring or optimization without public API changes label Sep 19, 2024
@fktn-k fktn-k added this to the Release v0.3.12 milestone Sep 19, 2024
Copy link

github-actions bot commented Sep 19, 2024

:octocat: Upload Coverage Event Notification

Coverage data has been uploaded for the commit feb0187cfbbff24a68e4be4b25ddce3894c508f4.
You can download the artifact which contains the same file uploaded to the Coveralls and its HTML version.

Name fkYAML_coverage.pr394.zip
ID 1957793065
URL https://github.com/fktn-k/fkYAML/actions/runs/10958197573/artifacts/1957793065

@fktn-k fktn-k force-pushed the reduce_string_copy_in_parse branch from 1d2b10d to fb03d72 Compare September 19, 2024 16:13
@fktn-k fktn-k force-pushed the reduce_string_copy_in_parse branch from b7c70b4 to 5f3e803 Compare September 19, 2024 16:39
@fktn-k fktn-k force-pushed the reduce_string_copy_in_parse branch from 743e97e to 014b1d3 Compare September 20, 2024 11:09
@fktn-k fktn-k force-pushed the reduce_string_copy_in_parse branch from 014b1d3 to feb0187 Compare September 20, 2024 11:11
@fktn-k fktn-k merged commit 9239264 into develop Sep 20, 2024
165 checks passed
@fktn-k fktn-k deleted the reduce_string_copy_in_parse branch September 20, 2024 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement refactoring or optimization without public API changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant