Comments (11)
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.
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.
In my case, a new context is created for every call. Hence, this would be of great help. Thanks
from quickjs_es_runtime.
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.
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.
todo, check if module (eval and execution) still works if we drop the buffer
from quickjs_es_runtime.
Great. Will test it out and let you know.
from quickjs_es_runtime.
Made the below changes
- Pass the current realm ref to CompiledModuleLoader functions (required to compile the source when loading for the first time)
- Return the bytes as Arc<Vec> instead of &Vec
from quickjs_es_runtime.
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.
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.
Thanks, closing this for now... as we have CompiledModuleLoader in place.
from quickjs_es_runtime.
Related Issues (20)
- Leaked promise inside a dropped context causes panic! HOT 7
- timeouts on invocations like call_function and eval HOT 2
- Option to disable features - console, setTimeout, setInterval HOT 9
- add console_formatter / console_logger to builder HOT 1
- Feat: function and struct to compute memory usage HOT 1
- Feat: TypedArrays HOT 1
- Panicked when running multiple promises concurrently HOT 2
- Document js_utils methods
- deprecate EsValueFacade HOT 1
- Segmentation fault: 11 & panic when using ScriptModuleLoader<QuickJsRealmAdapter> HOT 7
- fix MemoryUsage impl
- respect memory limit
- Main thread gets stuck randomly while awaiting for promise HOT 18
- thread panic occurred HOT 6
- Support for serde_json HOT 10
- Unexpected error logs even when the promise rejection is handled HOT 7
- Tokio Version in cargo.toml HOT 5
- Typescript support HOT 7
- fork quickjs HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from quickjs_es_runtime.