Skip to content

Stop reading buttons back out of the pointer payload under construction - #58297

Open
christophpurrer wants to merge 1 commit into
react:mainfrom
christophpurrer:export-D118471070
Open

Stop reading buttons back out of the pointer payload under construction#58297
christophpurrer wants to merge 1 commit into
react:mainfrom
christophpurrer:export-D118471070

Conversation

@christophpurrer

Copy link
Copy Markdown
Contributor

Summary:
WARNING: Generated by Autopilot (alpha) — review carefully, verify the underlying claim before accepting.
Agent: React Native Agent (Bugs) | Trajectory: https://www.internalfb.com/intern/devai/devmate/inspector/8e9d02d0-ad79-40df-b2c0-8dbc0f0c39d1/ | SC job: https://www.internalfb.com/intern/sandcastle/instance/54043196151461660/


PointerEvent.createW3CPointerEvent built its payload map, then read one field
straight back out of that same half-built map to compute another field:

pointerEvent.putInt("buttons", getButtons(_eventName, pointerType, buttonState))
...
getPressure(pointerEvent.getInt("buttons"), _eventName)

Reading from a WritableNativeMap while still writing to it is not free and not
safe:

  • ReadableNativeMap.getInt materialises the whole map across JNI
    (importKeys + importValues) and memoises the result in keysStorage /
    localMapStorage. Every subsequent put* on the same instance then leaves
    those caches stale, so a later Kotlin-side read of the map (hasKey,
    toHashMap) does not see pressure, tangentialPressure,
    hitPathForEventListener or the modifier keys.
  • It happens on the pointer-event hot path, once per pointer index per dispatch,
    purely to recover a value the caller already has in hand.

Keep the value in a local and pass it to getPressure directly. The payload is
byte-for-byte identical: getInt returns exactly the Int that putInt stored,
so getPressure receives the same argument as before.

Changelog:
[Internal]

Differential Revision: D118471070

…tion

Summary:
WARNING: Generated by Autopilot (alpha) — review carefully, verify the underlying claim before accepting.
Agent: React Native Agent (Bugs) | Trajectory: https://www.internalfb.com/intern/devai/devmate/inspector/8e9d02d0-ad79-40df-b2c0-8dbc0f0c39d1/ | SC job: https://www.internalfb.com/intern/sandcastle/instance/54043196151461660/

---

`PointerEvent.createW3CPointerEvent` built its payload map, then read one field
straight back out of that same half-built map to compute another field:

```
pointerEvent.putInt("buttons", getButtons(_eventName, pointerType, buttonState))
...
getPressure(pointerEvent.getInt("buttons"), _eventName)
```

Reading from a `WritableNativeMap` while still writing to it is not free and not
safe:

- `ReadableNativeMap.getInt` materialises the *whole* map across JNI
  (`importKeys` + `importValues`) and memoises the result in `keysStorage` /
  `localMapStorage`. Every subsequent `put*` on the same instance then leaves
  those caches stale, so a later Kotlin-side read of the map (`hasKey`,
  `toHashMap`) does not see `pressure`, `tangentialPressure`,
  `hitPathForEventListener` or the modifier keys.
- It happens on the pointer-event hot path, once per pointer index per dispatch,
  purely to recover a value the caller already has in hand.

Keep the value in a local and pass it to `getPressure` directly. The payload is
byte-for-byte identical: `getInt` returns exactly the `Int` that `putInt` stored,
so `getPressure` receives the same argument as before.

Changelog:
[Internal]

Differential Revision: D118471070
@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 Sep 2, 2026
@meta-codesync

meta-codesync Bot commented Sep 2, 2026

Copy link
Copy Markdown

@christophpurrer has exported this pull request. If you are a Meta employee, you can view the originating Diff in D118471070.

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. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant