ssr-rs icon indicating copy to clipboard operation
ssr-rs copied to clipboard

WIP(feat): Store Isolate inside API struct which can be reused

Open Auspicus opened this issue 2 years ago • 2 comments

Having the library user keep track of the Isolate instance improves performance by 5x from my tests in the benches. This could be further improved by multi-threading since the user can create a new Isolate (SSREnvironment) for each thread. We need to figure out an example to provide. There's a few more performance tweaks to be had:

  • [ ] Reusing CachedData for script compilation
  • [ ] Reusing Context

Auspicus avatar Jul 15 '22 12:07 Auspicus

Codecov Report

Merging #8 (3078924) into main (09a13e0) will increase coverage by 9.19%. The diff coverage is 97.91%.

@@            Coverage Diff             @@
##             main       #8      +/-   ##
==========================================
+ Coverage   89.28%   98.48%   +9.19%     
==========================================
  Files           2        2              
  Lines          84       66      -18     
==========================================
- Hits           75       65      -10     
+ Misses          9        1       -8     
Impacted Files Coverage Δ
src/ssr.rs 97.22% <97.14%> (+13.88%) :arrow_up:
tests/lib_check.rs 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 09a13e0...3078924. Read the comment docs.

codecov-commenter avatar Jul 16 '22 08:07 codecov-commenter

As we discussed, using this in a multi-threaded environment is actually quite difficult because of the way that async runtimes (ie. tokio) handle requests. There's no guarantee that the thread that starts handling a request will follow it all the way through to response if there's a yield as another thread from the thread pool might pick it up after the yield. Each v8 Isolate requires Isolate::Enter and Isolate::Exit to be called when accessed by a new thread. We need to figure out how to handle that :o

Auspicus avatar Jul 16 '22 08:07 Auspicus