Skip to content

Fix non-deterministic placeholder resource ID assignment in Placehold…#482

Open
oliviernotteghem wants to merge 1 commit intobazelbuild:mainfrom
oliviernotteghem:determinism
Open

Fix non-deterministic placeholder resource ID assignment in Placehold…#482
oliviernotteghem wants to merge 1 commit intobazelbuild:mainfrom
oliviernotteghem:determinism

Conversation

@oliviernotteghem
Copy link
Copy Markdown
Contributor

…erIdFieldInitializerBuilder

Summary:
Intent:

  • Fix non-deterministic placeholder resource ID assignment in R.java generation that caused remote cache misses and non-reproducible outputs across incremental builds.

Changes:

  • Replace LinkedHashMap with TreeMap for styleableAttrs and per-styleable attr maps, ensuring deterministic sorted iteration regardless of resource merge order.
  • Simplify assignAttrIds() by removing the inline/non-inline partition, which was itself non-deterministic (a side effect of first-come-first-served ReferenceResolver.shouldInline/markInlined semantics). All attrs are now assigned IDs in sorted order.

Test Plan:
Verified repeated builds of //apps/presidio/uberlite:bin_debug with remote cache disabled produce identical resources.jar outputs across multiple clean builds with Claude. USE_LOCAL_BAZEL=1 ./bazelw build uberlite builds successfully end-to-end.

Revert Plan:
Revert this PR via git revert <commit_sha>.

Jira Issues:


Generated by the 🪄 pr-create skill in devexp-agent-marketplace

…erIdFieldInitializerBuilder

Summary:
Intent:
- Fix non-deterministic placeholder resource ID assignment in R.java generation that caused remote cache misses and non-reproducible outputs across incremental builds.

Changes:
- Replace LinkedHashMap with TreeMap for styleableAttrs and per-styleable attr maps, ensuring deterministic sorted iteration regardless of resource merge order.
- Simplify assignAttrIds() by removing the inline/non-inline partition, which was itself non-deterministic (a side effect of first-come-first-served ReferenceResolver.shouldInline/markInlined semantics). All attrs are now assigned IDs in sorted order.

Test Plan:
Verified repeated builds of //apps/presidio/uberlite:bin_debug with remote cache disabled produce identical resources.jar outputs across multiple clean builds with Claude.
USE_LOCAL_BAZEL=1 ./bazelw build uberlite builds successfully end-to-end.

Revert Plan:
Revert this PR via `git revert <commit_sha>`.

Jira Issues:

---

<sub>Generated by the 🪄 [pr-create](https://sg.uberinternal.com/code.uber.internal/uber-code/devexp-agent-marketplace/-/blob/claude-code/plugins/dev/uber-dev/skills/pr-create/SKILL.md) skill in devexp-agent-marketplace</sub>
// Use TreeMap for deterministic iteration order. LinkedHashMap depends on
// insertion order from addStyleableResource() calls, which varies across builds
// due to non-deterministic resource merge ordering.
private final Map<String, Map<String, /*inlineable=*/ Boolean>> styleableAttrs = new TreeMap<>();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My initial thought is that TreeMap has a different lookup time complexity than LinkedHashMap, probably O(log N) vs O(1), respectively. This change would increase wall time, though I'm not sure how much this matters in terms of builds' critical time.

The follow-on question is whether the increased wall time cost exceeds that of recomputing with the current faster algorithm.

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