perf(web): zero-copy pixel path + consolidate js/wasmJs into webMain#2
Merged
Conversation
Write pdfium's pixel ArrayBuffer straight into Skia's wasm linear memory (via Data.makeUninitialized + Int8Array.set on awaitSkiko's memory buffer, pattern from coil3.decode.WebWorker), removing the intermediate Kotlin ByteArray + installPixels copy. One memcpy on the main thread instead of two. Also consolidate the js + wasmJs sources into a shared webMain: - PdfDocument, PdfiumGlue externals, ClipEntryText, and the Skiko zero-copy helper all live in webMain - jsMain/wasmJsMain reduced to a ~30-line PlatformBridge covering the three structural differences between the targets: typed-array to Kotlin primitive conversion (zero-cost unsafeCast on js vs bulk copy on wasmJs), the kotlinx.coroutines.await signature mismatch (papered over by an awaitTyped<T>() expect/actual), and Skiko's platform- specific awaitSkiko - pdfium js target switched to useEsModules() so a single @jsmodule annotation works for both targets without a jsMain-only @JsNonModule
…specifics Expand README to include clarification on web zero-copy rendering via Skia's wasm heap and the use of `Data.makeUninitialized`. Consolidate and refine platform-specific implementation details for `jvmMain`, `androidMain`, `iosMain`, and `webMain`.
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
ArrayBuffertransferred back from the pdfium worker is now written straight into Skia's wasm linear memory viaData.makeUninitialized+Int8Array.seton the buffer returned byorg.jetbrains.skiko.wasm.awaitSkiko. Pattern lifted from coil3.decode.WebWorker. One main-thread memcpy instead of two (dropped the intermediate KotlinByteArray+installPixelscopy).jsMain+wasmJsMainintowebMain: thePdfDocumentactual, thepdfium_glue.mjsexternals,ClipEntryText, and the Skiko zero-copy helper are now shared. Each leaf target keeps a ~30-linePlatformBridgethat covers only the genuine structural differences — typed-array conversion,kotlinx.coroutines.awaitsignature mismatch, and Skiko's platform-specificawaitSkiko.useEsModules()so a single@file:JsModule(\"./pdfium_glue.mjs\")declaration works for both targets without ajsMain-only@JsNonModulecompanion.Test plan
./gradlew :pdfium:compileKotlinJs :pdfium:compileKotlinWasmJspasses../gradlew :example:jsBrowserDevelopmentExecutableDistribution :example:wasmJsBrowserDevelopmentExecutableDistributionproduces a working bundle for both targets.