Giter Site home page Giter Site logo

Comments (11)

andrieshiemstra avatar andrieshiemstra commented on June 3, 2024 1

I instantiate only one runtime and create a new realm on every new call (for security reasons and to keep all the calls isolated & stateless).

I'm not sure how the cached annotation would work here as the parameters would include a realm.

i'll look into this later but to answer your question, you can create a custom key in that annotation

#[cached(
    key = "String",
    size = 10000,
    time = 3600,
    result = true,
    convert = r#"{ format!("{}://{}/{:?}", scheme, domain_port, session.get_env()) }"#
)]
async fn get_info(
    scheme: &str,
    domain_port: &str,
    session: GrecoSession,
) -> Result<OpenApi, JsError> {
   todo!()
}

from quickjs_es_runtime.

andrieshiemstra avatar andrieshiemstra commented on June 3, 2024

so the advantage would be the ability to load a compiled module from disk? for faster startup?

allthough i gues there are practical uses for that i would like to point out that while you say "loading and compiling on every invocation." modules are actually kept cached in every JSContext (Realm) in a loaded_modules list (see quickjs.c) and once compiled they are not compiled again unless you init a new Realm..

Havinbg said that i am still very much open to the idea of a CompiledModuleLoader (or as an option in scriptmodueloader)

from quickjs_es_runtime.

SreeniIO avatar SreeniIO commented on June 3, 2024

In my case, a new context is created for every call. Hence, this would be of great help. Thanks

from quickjs_es_runtime.

andrieshiemstra avatar andrieshiemstra commented on June 3, 2024

ok, i slammed the code in without testing or even trying to run it.. (so it needs some QC :)) but you could test to see if it works..

from quickjs_es_runtime.

andrieshiemstra avatar andrieshiemstra commented on June 3, 2024

todo: make from_bytecode accept a &Vec so we can alter CompiledModuleLoader to return a &Vec so you don't have to clone or create thge buffer every time you eval a compiled module

from quickjs_es_runtime.

andrieshiemstra avatar andrieshiemstra commented on June 3, 2024

todo, check if module (eval and execution) still works if we drop the buffer

from quickjs_es_runtime.

SreeniIO avatar SreeniIO commented on June 3, 2024

Great. Will test it out and let you know.

from quickjs_es_runtime.

SreeniIO avatar SreeniIO commented on June 3, 2024

Made the below changes

  1. Pass the current realm ref to CompiledModuleLoader functions (required to compile the source when loading for the first time)
  2. Return the bytes as Arc<Vec> instead of &Vec

from quickjs_es_runtime.

andrieshiemstra avatar andrieshiemstra commented on June 3, 2024

this issue does make me wonder if we're not overcomplicating things... we could also just make an option in the module loading logic to allways first compile modules to bytecode and cache that so it gets reused in every new realm (do you create a new realm for every new call or a new runtime?)

using a simple #[cached(size=100)] annotated function we could probably get the same performance benefit without the extra CompiledModuleLoader

from quickjs_es_runtime.

SreeniIO avatar SreeniIO commented on June 3, 2024

I instantiate only one runtime and create a new realm on every new call (for security reasons and to keep all the calls isolated & stateless).

I'm not sure how the cached annotation would work here as the parameters would include a realm.

from quickjs_es_runtime.

SreeniIO avatar SreeniIO commented on June 3, 2024

Thanks, closing this for now... as we have CompiledModuleLoader in place.

from quickjs_es_runtime.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.