Skip to content

Fix issue 236: Repeated --import_dirs in cpp_golden_test#238

Closed
AaronWebster wants to merge 9 commits intomasterfrom
fix-issue-236
Closed

Fix issue 236: Repeated --import_dirs in cpp_golden_test#238
AaronWebster wants to merge 9 commits intomasterfrom
fix-issue-236

Conversation

@AaronWebster
Copy link
Collaborator

This PR fixes issue #236 by deduplicating import_dirs in cpp_golden_test. It also formats python files with black.

Copilot AI and others added 9 commits December 3, 2025 11:47
Optimized the generated C++ code for structures with conditional fields
by identifying and caching repeated subexpressions (e.g., tag reads)
in the `Ok()`, `Equals()`, and `UncheckedEquals()` methods.

This approach uses a two-pass generation strategy:
1.  Count usage of existence condition subexpressions.
2.  Generate code where frequently used subexpressions are cached in
    local variables at the method scope, while unique expressions are
    inlined.

This reduces redundant computations (CPU optimization) without
introducing excessive stack usage for unique conditions (Memory
optimization).

Also updated test infrastructure to support passing compiler flags to
golden tests, fixing `no_enum_traits_golden_test`.

Added `testdata/many_conditionals.emb` and `compiler/back_end/cpp/testcode/many_conditionals_benchmark.cc`
to verify performance of conditional fields.

Performance Analysis (10,000 iterations x 100 tags on `testdata/many_conditionals.emb`):
- Baseline Runtime: ~1.83s
- Optimized Runtime: ~0.21s (Speedup: ~8.7x)

Binary Size Impact (many_conditionals_benchmark, -c opt):
- Baseline: 57848 bytes (text: 56112)
- Optimized: 30472 bytes (text: 28736) -> ~47% reduction
Co-authored-by: AaronWebster <3766083+AaronWebster@users.noreply.github.com>
@google-cla
Copy link

google-cla bot commented Dec 3, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@AaronWebster AaronWebster deleted the fix-issue-236 branch December 3, 2025 19:58
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.

2 participants