Skip to content

V2: go:wasmimport + custom runtime JS helpers based bindings #6

@BrownNPC

Description

@BrownNPC

InkWasm is a faster syscall/js replacement, it's a package and a generator.

This package could be really useful for implementing faster bindings. It has support for passing slices to JS out of the box.

This is really useful for implementing the remaining functions. Eg. the ones that require passing shader primatives to C

#5

//inkwasm:get globalThis.TestObject_GetRandom
func gen_GetRandom([]byte) Object

func Benchmark_BytesRandom_INKWASM(b *testing.B) {
	b.ReportAllocs()

	r := make([]byte, 10)
	for i := 0; i < b.N; i++ {
		gen_GetRandom(r)
	}
}
 globalThis.TestObject_GetRandom = function (e) {
        crypto.getRandomValues(e)
    }

this is almost 2x faster than using syscall/js because it avoids CopyBytesToGo(). Hence less memory allocations.

func Benchmark_BytesRandom_JS_SYSCALL(b *testing.B) {
	b.ReportAllocs()

	fn := js.Global().Get("TestObject_GetRandom")
	array := js.Global().Get("Uint8Array").New(10)
	r := make([]byte, 10)
	for i := 0; i < b.N; i++ {
		fn.Invoke(array)
		js.CopyBytesToGo(r, array)
	}
}
Benchmark_BytesRandom_INKWASM              100000         1026 ns/op          0 B/op         0 allocs/op
Benchmark_BytesRandom_JS_SYSCALL           100000         1808 ns/op         40 B/op         3 allocs/op

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions