-
Notifications
You must be signed in to change notification settings - Fork 27
Optimize C++ Backend for Conditional Fields #234
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
Closed
AaronWebster
wants to merge
13
commits into
google:master
from
AaronWebster:optimized-conditionals-v2-port
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
16b4e9b
Optimize conditional fields in C++ backend
AaronWebster c10398f
Format files
AaronWebster ed451be
Revert: Reformat compiler/back_end/cpp/header_generator.py to origina…
AaronWebster 855c369
Revert: Reformat compiler/back_end/cpp/run_one_golden_test.py to orig…
AaronWebster 1a5d4d1
Reformat: Wrap many_conditionals_benchmark.cc in namespace
AaronWebster e2a6b3b
Fix Python formatting with black
AaronWebster 3892894
Update C++ golden files for optimized conditionals
AaronWebster 049a59e
Initial plan
Copilot d941553
Merge branch 'optimized-conditionals-v2-port' of https://github.com/A…
Copilot cea399f
Fix Python formatting and regenerate golden files
Copilot 990e035
Merge pull request #1 from AaronWebster/copilot/fix-all-build-files-a…
AaronWebster bcd2b93
Merge remote-tracking branch 'origin/master' into optimized-condition…
AaronWebster bb5dc96
Merge branch 'google:master' into optimized-conditionals-v2-port
AaronWebster File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
compiler/back_end/cpp/testcode/many_conditionals_benchmark.cc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| #include <gtest/gtest.h> | ||
|
|
||
| #include <chrono> | ||
| #include <iostream> | ||
| #include <vector> | ||
|
|
||
| #include "testdata/many_conditionals.emb.h" | ||
|
|
||
| // A simple test that acts as a benchmark/sanity check. | ||
| // Since this file is in compiler/back_end/cpp/testcode/, it will be built as a | ||
| // cc_test. We can use GoogleTest macros. | ||
|
|
||
| namespace emboss { | ||
| namespace test { | ||
| namespace { | ||
|
|
||
| TEST(ComplexConditionals, PerformanceBenchmark) { | ||
| std::vector<char> buffer(100, 0); | ||
| auto view = emboss::test::MakeLargeConditionalsView(&buffer); | ||
|
|
||
| auto start = std::chrono::high_resolution_clock::now(); | ||
| int iterations = 10000; | ||
| volatile bool result = false; | ||
| for (int i = 0; i < iterations; ++i) { | ||
| for (int tag = 0; tag < 100; ++tag) { | ||
| view.tag().Write(tag); | ||
| result = view.Ok(); | ||
| } | ||
| } | ||
| auto end = std::chrono::high_resolution_clock::now(); | ||
|
|
||
| std::chrono::duration<double> elapsed = end - start; | ||
| // We don't strictly fail on time, but we print it. | ||
| // In a real CI system we might assert upper bounds. | ||
| std::cout << "Time for " << iterations | ||
| << " iterations (x100 tags): " << elapsed.count() << "s" | ||
| << std::endl; | ||
|
|
||
| EXPECT_TRUE(result); | ||
| EXPECT_TRUE(view.Ok()); | ||
| } | ||
|
|
||
| } // namespace | ||
| } // namespace test | ||
| } // namespace emboss |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I think this is intended to inline the contents of
has_<field>, is that correct? And the goal of that is to reuse a cached instance of a field that is referenced in multiplehas_<field>methods? Looking at the generated code now it's...pretty verbose. I'm actually a little surprised this would reduce code size.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check out #235 which I think is more correct as to what Ben suggested I implement and the code is much cleaner. Some compiler specific attributes could be elided, let me know.