fix(android): unblock WebView JS thread during bridge event dispatch#28
Open
modos189 wants to merge 1 commit into
Open
fix(android): unblock WebView JS thread during bridge event dispatch#28modos189 wants to merge 1 commit into
modos189 wants to merge 1 commit into
Conversation
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.
Problem
emitEventToNativeScriptruns on the JavaBridge thread. NativeScript dispatches the call to its V8 thread and blocks until the handler completes - store updates, native view property changes, etc.Under frequent bridge calls in complex scenes with many active scripts, this starves the WebView render pipeline by 10–30 ms per call, accumulating to hundreds of milliseconds of blocked time per second.
Fix
Wrap
onWebViewEventinsetTimeout(0)so the JavaBridge thread returns immediately and NativeScript processes the event on its next tick.Trade-off
Events become asynchronous relative to the WebView caller. Any code that relies on NativeScript state being updated synchronously after a bridge call would be affected. However, this path is architecturally one-way:
emitEventToNativeScriptis declaredvoidin the@JavascriptInterfacecontract, so no return value can be passed back to WebView JS regardless. The NativeScript -> WebView channel operates independently viaexecuteJavaScript.