Skip to content

Do not key WeakHashMap by Integer - #60223

Merged
meta-codesync[bot] merged 1 commit into
react:mainfrom
Yqwed:weakhashmap-identity
Nov 23, 2026
Merged

meta-codesync[bot] merged 1 commit into
react:mainfrom
Yqwed:weakhashmap-identity

Conversation

@Yqwed

@Yqwed Yqwed commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

After JEP-401 that will throw IdentityException. Also, int-s outside of [-128;128) are not cached and boxing creates new instances, meaning that GC is free to reclaim them immediately.

getStyleFromString only returns 7 different values and the map stores pair of int-s: using LruCache-s is overkill and SparseArray is fine.

#60220

Summary:

Do not key WeakHashMap by Integer as preparation for JEP-401

Changelog:

Do not key WeakHashMap by Integer as preparation for JEP-401.

Pick one each for the category and type tags:

[ANDROID][FIXED] -
Do not key WeakHashMap by Integer

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

Test Plan:

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 22, 2026
@Yqwed

Yqwed commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

@javache this is similar to #56196

@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Nov 22, 2026
@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Visual regression

No visual differences at a489e3cb8401.

ios: no capture

AndroidProgressBarManagerInterface<ProgressBarContainerView> {
@Suppress("IDENTITY_SENSITIVE_OPERATIONS_WITH_VALUE_TYPE")
private val measuredStyles = WeakHashMap<Int, Pair<Int, Int>>()
private val measuredStyles = ConcurrentHashMap<Int, Pair<Int, Int>>()

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.

Maybe let's just use a SparseArray, and synchronize on it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, changed to SparseArray + synchronized.

After JEP-401 that will throw IdentityException. Also, int-s
outside of [-128;128) are not cached and boxing creates new
instances, meaning that GC is free to reclaim them immediately.

getStyleFromString only returns 7 different values and the map
stores pair of int-s: using LruCache-s is overkill and
SparseArray is fine.

react#60220
@Yqwed
Yqwed force-pushed the weakhashmap-identity branch 2 times, most recently from 02f559e to a489e3c Compare November 23, 2026 11:19
@meta-codesync

meta-codesync Bot commented Nov 23, 2026

Copy link
Copy Markdown

@javache has imported this pull request. If you are a Meta employee, you can view this in D133975563.

@christophpurrer christophpurrer left a comment

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.

Review automatically exported from Phabricator review in Meta.

@Yqwed

Yqwed commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thank you, @javache and @christophpurrer !

@meta-codesync
meta-codesync Bot merged commit 375d0a9 into react:main Nov 23, 2026
60 checks passed
@react-native-bot

Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @Yqwed in 375d0a9

When will my fix make it into a release? | How to file a pick request?

@Yqwed

Yqwed commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

I've created cherry-pick requests into 0.87-0.89 branches.

@Yqwed
Yqwed deleted the weakhashmap-identity branch November 23, 2026 18:32
gabrieldonadel pushed a commit that referenced this pull request Nov 23, 2026
After JEP-401 that will throw IdentityException. Also, int-s outside of [-128;128) are not cached and boxing creates new instances, meaning that GC is free to reclaim them immediately.

getStyleFromString only returns 7 different values and the map stores pair of int-s: using LruCache-s is overkill and SparseArray is fine.

#60220

<!-- Thanks for submitting a pull request! We appreciate you spending the time to work on these changes. Please provide enough information so that others can review your pull request. The three fields below are mandatory. -->

## Summary:

Do not key WeakHashMap by Integer as preparation for JEP-401

<!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? -->

## Changelog:

Do not key WeakHashMap by Integer as preparation for JEP-401.

Pick one each for the category and type tags:

[ANDROID][FIXED] -
Do not key WeakHashMap by Integer

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

## Test Plan:

<!-- Demonstrate the code is solid. Example: The exact commands you ran and their output, screenshots / videos if the pull request changes the user interface. -->

Differential Revision: D133975563

Pull Request resolved: #60223

(cherry picked from commit 375d0a9)
@react-native-bot

Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @Yqwed in 7517aa3

When will my fix make it into a release? | How to file a pick request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants