swiftwasm / swiftwasm/JavaScriptKit

[BridgeJS] Pass String parameters unretained by default

オープン
#677 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
Swift
スター
986
フォーク
76
平均マージ
21時間 11分
マージ済み PR(30日)
4

説明

When calling a JS function through BridgeJS with String parameters, every String is

  • lowered by calling _swift_js_make_js_string
  • which decodes and retains in JS object store (new entry, new ref = 1)
  • the object store ref is passed as wasm parameter
  • the JS thunk immediately get the object and releases (count--, remove from store)

this is very wasteful, and makes retain the number one bottleneck in current ElementaryUI performance benchmarks.

Example:

@JSFunction func hello(_ v: String) throws

// generates
func _$hello(_ v: String) throws(JSException) -> Void {
    let vValue = v.bridgeJSLowerParameter()
    bjs_hello(vValue)
    if let error = _swift_js_take_exception() {
        throw error
    }
}
function bjs_hello(v) {
    try {
        const vObject = swift.memory.getObject(v);
        swift.memory.release(v);
        imports.hello(vObject);
    } catch (error) {
        setException(error);
    }
}

I suggest:

  • passing String always "in-line" (ie: as address + length) without retaining in the JS memory store
  • still support JSString by-ref to control Swift caller caching (ie: retain once and use same ref multiple times)

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

Start by tracing _swift_js_make_js_string, bridgeJSLowerParameter, and the generated bjs_hello thunk shown in the issue, then inspect how JSString references are represented. Done means ordinary String parameters cross the bridge without a JS memory-store retain/release cycle while JSString still supports caller-controlled by-reference reuse; verify the impact against the ElementaryUI performance benchmarks.

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript, swift, wasm
領域
api, performance, web-dev
issue の種類
リファクタリング
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
28/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。