GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — BridgeJS: Optimize numeric array transfer with bulk TypedArray copy by krodak · Pull Request #745 · swiftwasm/JavaScriptKit

Conversation

@krodak

@krodak krodak commented May 13, 2026

Copy link
Copy Markdown
Member

Overview

Optimize numeric array transfer by using bulk TypedArray memory copy instead of element-by-element stack serialization. When a Swift function passes or receives a numeric array ([Int], [UInt8], [Float], [Double], etc.), BridgeJS now transfers the data as a single bulk operation. TypeScript types remain number[] / bigint[] — no user-facing API change.

This is a transparent performance optimization following the same pattern as bridgeJSStackPopAsOptional — a specialized ABI for numeric element types without changing the type contract. Non-numeric arrays ([String], [MyStruct], etc.) continue using the existing element-by-element stack protocol.

1. Swift → JS direction: Array.bridgeJSTypedArrayPush() calls withUnsafeBufferPointer to pass (ptr, count, kind) to a new swift_js_push_typed_array WASM import, which copies the bytes into a JS TypedArray. A pre-allocated for-loop then converts to number[] for the caller.

2. JS → Swift direction: [T].bridgeJSTypedArrayLiftParameter(sourceId, count) receives a retained TypedArray from JS, allocates via Array(unsafeUninitializedCapacity:), and calls back to JS via swift_js_init_typed_array_memory to bulk copy — the same retain-allocate-callback pattern used by string lowering.

3. Affected types: All integer types (Int8 through Int64, signed and unsigned), Float, Double, plus pointer-width Int/UInt. A new _BridgeJSTypedArrayElement protocol marks eligible types. BridgeType.isNumericScalar and typedArrayKind on the skeleton side route the codegen.

Benchmark results

Release build, 10K iterations × 5 runs:

Test Before After Speedup
takeIntArray (1K, JS→Swift) 758 ms 13 ms 58×
takeDoubleArray (1K, JS→Swift) 791 ms 13 ms 61×
makeIntArray (1K, Swift→JS) 221 ms 18 ms 12×
makeIntArrayLarge (10K, Swift→JS) 2160 ms 146 ms 15×
roundtripIntArray (1K) 964 ms 29 ms 33×
takeStringArray (non-numeric) 23 ms 25 ms unchanged

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

MaxDesiatov reacted with heart emoji
All reactions
  • ❤️ 1 reaction
@krodak
krodak requested a review from kateinoigakukun May 13, 2026 09:09
@krodak krodak self-assigned this May 13, 2026
@krodak
krodak force-pushed the krodak/typed-array branch from 16d3b1e to 785e1e2 Compare May 13, 2026 10:21
@krodak
krodak requested a review from MaxDesiatov May 13, 2026 10:31
kateinoigakukun
kateinoigakukun reviewed May 13, 2026
View reviewed changes
Comment thread Plugins/BridgeJS/Sources/BridgeJSCore/ClosureCodegen.swift Resolved

Uh oh!

There was an error while loading. Please reload this page.

@krodak
krodak force-pushed the krodak/typed-array branch 3 times, most recently from 937dadc to 8cb4535 Compare May 13, 2026 18:57
@krodak
BridgeJS: Optimize numeric array transfer with bulk TypedArray copy
2e74754
@krodak
krodak force-pushed the krodak/typed-array branch from 8cb4535 to 2e74754 Compare May 13, 2026 19:10
kateinoigakukun
kateinoigakukun approved these changes May 13, 2026
View reviewed changes
@kateinoigakukun
kateinoigakukun merged commit 403ae95 into main May 13, 2026
13 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@kateinoigakukun
kateinoigakukun deleted the krodak/typed-array branch May 13, 2026 20:58
@krodak krodak mentioned this pull request Nov 6, 2026
BridgeJS: Normalize pointer in swift_js_push_typed_array #828
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@kateinoigakukun kateinoigakukun kateinoigakukun approved these changes
@MaxDesiatov MaxDesiatov Awaiting requested review from MaxDesiatov

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@krodak krodak

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@krodak @kateinoigakukun
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.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.