[llvm-profdata] Move error handling logic out of normal input's code path #67177
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Based on disassembly and profiling results, it looks like the cost of std::error_code and llvm::ErrorOr<> are non-trivial, as it involves virtual function calls that are not optimized in -O3.
This patch moves error handling logic into the conditional branch in error checking, only generates std::error_code on actual error instead of the default case to generate sampleprof_error::success.
In the next patch I am looking to change the API to uses a plain old enum for error checking instead, because based on profiling results error handling related code accounts for 7-8% of the profile loading time even if there's no error at all.