Stop reading buttons back out of the pointer payload under construction - #58297
Open
christophpurrer wants to merge 1 commit into
Open
Stop reading buttons back out of the pointer payload under construction#58297christophpurrer wants to merge 1 commit into
buttons back out of the pointer payload under construction#58297christophpurrer wants to merge 1 commit into
Conversation
…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
|
@christophpurrer has exported this pull request. If you are a Meta employee, you can view the originating Diff in D118471070. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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.createW3CPointerEventbuilt its payload map, then read one fieldstraight back out of that same half-built map to compute another field:
Reading from a
WritableNativeMapwhile still writing to it is not free and notsafe:
ReadableNativeMap.getIntmaterialises the whole map across JNI(
importKeys+importValues) and memoises the result inkeysStorage/localMapStorage. Every subsequentput*on the same instance then leavesthose caches stale, so a later Kotlin-side read of the map (
hasKey,toHashMap) does not seepressure,tangentialPressure,hitPathForEventListeneror the modifier keys.purely to recover a value the caller already has in hand.
Keep the value in a local and pass it to
getPressuredirectly. The payload isbyte-for-byte identical:
getIntreturns exactly theIntthatputIntstored,so
getPressurereceives the same argument as before.Changelog:
[Internal]
Differential Revision: D118471070