-
Notifications
You must be signed in to change notification settings - Fork 255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clarify the scope of stdin/stdout for dynamically linked modules #2293
Comments
Looking at my own writing above, I see that I need to do a little investigation to see how this is wired up at the Javy side, but I'll keep this open and I welcome any tips. |
I have done some investigating, and I'm guess the current behaviour is as expected with the current API: The executing function gets the fs/stdin/etc. from the module it's invoked. What could possibly work and be worth while would be something ala: RegisterModule(name, compiled) Which when requested as an import, and not found in the regular instance map, would be instansiated with most of the config inherited from the importer. |
Some upstream (Hugo) benchmarks: ``` name old time/op new time/op delta KatexStartStop/PoolSize1-10 19.5ms ± 6% 19.4ms ± 3% ~ (p=1.000 n=4+4) KatexStartStop/PoolSize8-10 116ms ± 6% 55ms ± 3% -52.61% (p=0.029 n=4+4) KatexStartStop/PoolSize16-10 222ms ± 3% 95ms ± 6% -57.07% (p=0.029 n=4+4) name old alloc/op new alloc/op delta KatexStartStop/PoolSize1-10 12.2MB ± 0% 12.2MB ± 0% -0.22% (p=0.029 n=4+4) KatexStartStop/PoolSize8-10 97.9MB ± 0% 73.9MB ± 0% -24.46% (p=0.029 n=4+4) KatexStartStop/PoolSize16-10 196MB ± 0% 148MB ± 0% -24.15% (p=0.029 n=4+4) name old allocs/op new allocs/op delta KatexStartStop/PoolSize1-10 18.1k ± 0% 17.4k ± 0% -3.45% (p=0.029 n=4+4) KatexStartStop/PoolSize8-10 144k ± 0% 18k ± 0% -87.65% (p=0.029 n=4+4) KatexStartStop/PoolSize16-10 289k ± 0% 18k ± 0% -93.67% (p=0.029 n=4+4) ``` See tetratelabs#2293
Some upstream (Hugo) benchmarks: ``` name old time/op new time/op delta KatexStartStop/PoolSize1-10 19.5ms ± 6% 19.4ms ± 3% ~ (p=1.000 n=4+4) KatexStartStop/PoolSize8-10 116ms ± 6% 55ms ± 3% -52.61% (p=0.029 n=4+4) KatexStartStop/PoolSize16-10 222ms ± 3% 95ms ± 6% -57.07% (p=0.029 n=4+4) name old alloc/op new alloc/op delta KatexStartStop/PoolSize1-10 12.2MB ± 0% 12.2MB ± 0% -0.22% (p=0.029 n=4+4) KatexStartStop/PoolSize8-10 97.9MB ± 0% 73.9MB ± 0% -24.46% (p=0.029 n=4+4) KatexStartStop/PoolSize16-10 196MB ± 0% 148MB ± 0% -24.15% (p=0.029 n=4+4) name old allocs/op new allocs/op delta KatexStartStop/PoolSize1-10 18.1k ± 0% 17.4k ± 0% -3.45% (p=0.029 n=4+4) KatexStartStop/PoolSize8-10 144k ± 0% 18k ± 0% -87.65% (p=0.029 n=4+4) KatexStartStop/PoolSize16-10 289k ± 0% 18k ± 0% -93.67% (p=0.029 n=4+4) ``` See tetratelabs#2293
Some upstream (Hugo) benchmarks: ``` name old time/op new time/op delta KatexStartStop/PoolSize1-10 19.5ms ± 6% 19.4ms ± 3% ~ (p=1.000 n=4+4) KatexStartStop/PoolSize8-10 116ms ± 6% 55ms ± 3% -52.61% (p=0.029 n=4+4) KatexStartStop/PoolSize16-10 222ms ± 3% 95ms ± 6% -57.07% (p=0.029 n=4+4) name old alloc/op new alloc/op delta KatexStartStop/PoolSize1-10 12.2MB ± 0% 12.2MB ± 0% -0.22% (p=0.029 n=4+4) KatexStartStop/PoolSize8-10 97.9MB ± 0% 73.9MB ± 0% -24.46% (p=0.029 n=4+4) KatexStartStop/PoolSize16-10 196MB ± 0% 148MB ± 0% -24.15% (p=0.029 n=4+4) name old allocs/op new allocs/op delta KatexStartStop/PoolSize1-10 18.1k ± 0% 17.4k ± 0% -3.45% (p=0.029 n=4+4) KatexStartStop/PoolSize8-10 144k ± 0% 18k ± 0% -87.65% (p=0.029 n=4+4) KatexStartStop/PoolSize16-10 289k ± 0% 18k ± 0% -93.67% (p=0.029 n=4+4) ``` See tetratelabs#2293
Some upstream (Hugo) benchmarks: ``` name old time/op new time/op delta KatexStartStop/PoolSize1-10 19.5ms ± 6% 19.4ms ± 3% ~ (p=1.000 n=4+4) KatexStartStop/PoolSize8-10 116ms ± 6% 55ms ± 3% -52.61% (p=0.029 n=4+4) KatexStartStop/PoolSize16-10 222ms ± 3% 95ms ± 6% -57.07% (p=0.029 n=4+4) name old alloc/op new alloc/op delta KatexStartStop/PoolSize1-10 12.2MB ± 0% 12.2MB ± 0% -0.22% (p=0.029 n=4+4) KatexStartStop/PoolSize8-10 97.9MB ± 0% 73.9MB ± 0% -24.46% (p=0.029 n=4+4) KatexStartStop/PoolSize16-10 196MB ± 0% 148MB ± 0% -24.15% (p=0.029 n=4+4) name old allocs/op new allocs/op delta KatexStartStop/PoolSize1-10 18.1k ± 0% 17.4k ± 0% -3.45% (p=0.029 n=4+4) KatexStartStop/PoolSize8-10 144k ± 0% 18k ± 0% -87.65% (p=0.029 n=4+4) KatexStartStop/PoolSize16-10 289k ± 0% 18k ± 0% -93.67% (p=0.029 n=4+4) ``` See tetratelabs#2293
See https://github.com/bep/javywazeroissue/blob/58a6147e45096a2dbfc4d106002898c8f960b677/lib.go#L43
I'm pasting the relevant lines here for discussion:
The above works and is more or less the "hello world" example from https://github.com/bytecodealliance/javy.
To me, the
foo
module is the running instance, yet it uses stdin/stdout from the dynamically linked module, which I find surprising, and makes it impossible to init multiple JS modules (either different modules, or multiple instances of the same) in the same runtime.I have implemented a proof of concept on this for inclusion in Hugo, with a simple RPC dispatcher over stdin/stdout, and it mostly works great. But for slower running scripts (e.g. Katex), I would want to have multiple instances of the script.1 And with the above, I need to create a new runtime per instance (with a shared compilation cache). This works, but is resource heavy:
Ideally I would want to do something ala:
Footnotes
Yes, I have looked at https://github.com/suborbital/javy and https://github.com/F21/javy-wazero, but the bytecodealliance/Shopify fork seems to be the active one, and I don't think the
suborbital
fork would help with the main problem above. ↩The text was updated successfully, but these errors were encountered: