llrt icon indicating copy to clipboard operation
llrt copied to clipboard

JS lambda runtime to Rust

Open yollotltam opened this issue 2 years ago • 2 comments

This is a work in progress.

Issue # (if available)

Description of changes

This PR migrates the current runtime of js to rust.

  • Add runtime in Rust.
  • Change the call of js/@llrt/runtime.ts to src/runtime.rs

Checklist

  • [ ] Created unit tests in tests/unit and/or in Rust for my feature if needed
  • [x] Ran make fix to format JS and apply Clippy auto fixes
  • [ ] Made sure my code didn't add any additional warnings: make check
  • [ ] Updated documentation if needed (API.md/README.md/Other)

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

yollotltam avatar Mar 11 '24 16:03 yollotltam

I've converted this PR to a draft because the implementation is not complete. It looks like returning responses, and errors are not implemented.

calavera avatar Mar 11 '24 18:03 calavera

I've converted this PR to a draft because the implementation is not complete. It looks like returning responses, and errors are not implemented.

Yeah that's true, I should have made it like that since the beginning :sweat_smile:

yollotltam avatar Mar 11 '24 18:03 yollotltam

I would recommend to adopt Tower service trait for runtime implementation. It is battle tested and extensible with the Tower eco-system.

To support both buffered response and streaming response, the response from the handler should be a trait like IntoResponse.

Lambda Rust runtime is a good starting point. Recommend to take a look.

bnusunny avatar Mar 14 '24 15:03 bnusunny

I would recommend to adopt Tower service trait for runtime implementation. It is battle tested and extensible with the Tower eco-system.

I recon this would a bit to much complexity for the capabilities that we need. Although, I have not worked with tower before so can't make the best judgement. @bnusunny how "heavy" is it in terms of deps and increased binary size?

richarddavison avatar Mar 14 '24 19:03 richarddavison

Tower is a light package. Here is the cargo-depsize results (including Tower). We won't know the true impact on binary size until we use it in llrt.

dev-dsk-sunhua-2c-13f440bb % cargo depsize
async-trait (v0.1.77)     : 113.58KB (116306 bytes)
base64-simd (v0.8.0)      : 55.52KB (56848 bytes)
bytes (v1.5.0)            : 277.95KB (284617 bytes)
chrono (v0.4.35)          : 1.24MB (1302260 bytes)
crc32c (v0.6.5)           : 26.80KB (27441 bytes)
crc32fast (v1.4.0)        : 95.54KB (97828 bytes)
fxhash (v0.2.1)           : 15.14KB (15506 bytes)
hex-simd (v0.8.0)         : 32.01KB (32781 bytes)
http-body-util (v0.1.0)   : 44.63KB (45706 bytes)
hyper (v1.2.0)            : 670.01KB (686093 bytes)
hyper-rustls (v0.26.0)    : 85.04KB (87082 bytes)
hyper-util (v0.1.3)       : 263.48KB (269808 bytes)
itoa (v1.0.10)            : 28.27KB (28946 bytes)
libc (v0.2.153)           : 4.01MB (4200306 bytes)
md-5 (v0.10.6)            : 38.83KB (39761 bytes)
once_cell (v1.19.0)       : 138.40KB (141719 bytes)
phf (v0.11.2)             : 77.80KB (79665 bytes)
quick-xml (v0.31.0)       : 1.02MB (1068631 bytes)
ring (v0.17.8)            : 11.75MB (12319198 bytes)
rquickjs (v0.5.1)         : 38.76KB (39687 bytes)
rustls (v0.22.2)          : 1.44MB (1505845 bytes)
ryu (v1.0.17)             : 157.60KB (161378 bytes)
simd-json (v0.13.8)       : 868.60KB (889448 bytes)
snmalloc-rs (v0.3.5)      : 17.29KB (17708 bytes)
socket2 (v0.5.6)          : 271.50KB (278012 bytes)
tokio (v1.36.0)           : 3.74MB (3916694 bytes)
tokio-context (v0.1.3)    : 37.44KB (38340 bytes)
tokio-rustls (v0.25.0)    : 106.61KB (109167 bytes)
tower (v0.4.13)           : 469.36KB (480620 bytes)
tower-layer (v0.3.2)      : 23.06KB (23610 bytes)
tower-service (v0.3.2)    : 19.53KB (19994 bytes)
tracing (v0.1.40)         : 435.52KB (445970 bytes)
tracing-core (v0.1.32)    : 239.24KB (244978 bytes)
uname (v0.1.1)            : 14.80KB (15156 bytes)
url (v2.5.0)              : 547.96KB (561108 bytes)
uuid (v1.7.0)             : 215.26KB (220430 bytes)
uuid-simd (v0.8.0)        : 29.40KB (30102 bytes)
webpki (v0.22.4)          : 254.94KB (261058 bytes)
webpki-roots (v0.26.1)    : 500.70KB (512716 bytes)
zstd (v0.13.0)            : 114.65KB (117399 bytes)
> Total size: 29.36MB (30789922 bytes)

bnusunny avatar Mar 15 '24 07:03 bnusunny

We can expect some pretty nice perf improvements for this change, especially in the upper percentiles rs-runtime-client

richarddavison avatar Mar 28 '24 21:03 richarddavison