Skip to content

Improve Interop Html Elements performance by avoiding wasm2js#3003

Open
ApoloApps wants to merge 3 commits intoJetBrains:jb-mainfrom
ApoloApps:perfForInteropHtmls
Open

Improve Interop Html Elements performance by avoiding wasm2js#3003
ApoloApps wants to merge 3 commits intoJetBrains:jb-mainfrom
ApoloApps:perfForInteropHtmls

Conversation

@ApoloApps
Copy link
Copy Markdown

Improves performance of HtmlInteropElements by avoiding the wasm2js boundary as much as possible (since operations done are already costly on js side so we don't want to add more overhead than needed). Since some border functions were called in a place where the logic could be done in js, I've migrated it to a single js with optimizations like boolean packing for less boundary overhead
Fixes https://youtrack.jetbrains.com/issue/CMP-9757/Web-InteropElements-amount-for-a-lot-of-the-frame-time-cost

Before (check issue for more examples too, consistent 6-10ms with small 3ms and big as 15ms)
Screenshot 2026-04-22 205638
Screenshot 2026-04-22 205628
Screenshot 2026-04-22 205831
Screenshot 2026-04-22 205821
Screenshot 2026-04-22 205811

After (consistent 0.4ms to 1.8 ms with small peaks with 2-3ms and as low as a few microseconds. It maintains constant time pretty well)
Screenshot 2026-04-22 204140
Screenshot 2026-04-22 204116
Screenshot 2026-04-22 204057
Screenshot 2026-04-22 204042
Screenshot 2026-04-22 192319
Screenshot 2026-04-22 004059

Testing

Manually tested

Release Notes

N/A

… Added optimizations for the boundary too, like packing.
… (e: file:///home/runner/work/compose-multiplatform-core/compose-multiplatform-core/compose/ui/ui/src/webMain/kotlin/androidx/compose/ui/viewinterop/WebInteropElementHolder.web.kt:209:1 Missing return statement.)
@eymar eymar self-requested a review April 23, 2026 09:51
if (posChng) {
const left = nwPosX / dens;
const top = nwPosY / dens;
wrpEl.style.transform = "matrix(1, 0, 0, 1, " + left + ", " + top + ")";
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This does not cause layout reflow so it is much more performant. (gonna use it in another future a11y PR I'll be submitting too)

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.

1 participant