swiftwasm / swiftwasm/JavaScriptKit
[BridgeJS] Pass String parameters unretained by default
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Swift
- Estrellas
- 986
- Forks
- 76
- Merge medio
- 21 h 11 min
- PR fusionados (30 d)
- 4
Descripción
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
Stringalways "in-line" (ie: as address + length) without retaining in the JSmemorystore - still support
JSStringby-ref to control Swift caller caching (ie: retain once and use same ref multiple times)
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- javascript, swift, wasm
- Área
- api, performance, web-dev
- Tipo de issue
- Refactorización
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 28/100