swiftwasm / swiftwasm/JavaScriptKit

[BridgeJS] Pass String parameters unretained by default

Đang mở
#677 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
Swift
Star
986
Fork
76
Merge trung bình
21 giờ 11 phút
Pull request đã merge (30 ngày)
4

Mô tả

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)

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
javascript, swift, wasm
Lĩnh vực
api, performance, web-dev
Loại issue
Tái cấu trúc
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
28/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.