long delay before and after script execution
See original GitHub issueI have noticed that importing this library will cause a long delay before my script is executed. I assume the delay before the script executes is because the wasm file is dynamically imported automatically
const Canvas = await lib.CanvasKitInit({}) as CanvasKit;
I do not know why there is an extra delay after my script executes though.
To illustrate how long the delays are, here is a simple benchmark. First the script using your library:
import Canvas from 'https://deno.land/x/canvas@v1.1.1/mod.ts'
console.log(Date.now(), 'imports complete')
const canvas = Canvas.MakeCanvas(200, 200);
const ctx = canvas.getContext('2d');
console.log(Date.now(), 'created canvas & context')
ctx.fillStyle = 'red';
ctx.fillRect(10, 10, 200 - 20, 200 - 20);
await Deno.writeFile('image.png', canvas.toBuffer())
console.log(Date.now(), 'deno wrote buffer to png')
and a bash script timing the usage:
#!/bin/bash
millis() {
echo $(($(date +%s%N)/1000000)) $1
}
deno install -f --allow-write ./canvas.ts
millis 'before script'
canvas
millis 'after script'
Here is the output:
./timer.sh
✅ Successfully installed canvas
/home/andrew/.deno/bin/canvas
1615473303762 before script
1615473305209 imports complete
1615473305213 created canvas & context
1615473305251 deno wrote buffer to png
1615473308244 after script
Thats a 1.447
second delay during import and a 2.993
second delay after the script finishes executing.
If these delays are absolutely necessary, it would be nice if we could at least control the lifecycle. E.g. instead of implicit importing and cleanup, expose an api for loading and cleanup:
import Canvas from 'https://deno.land/x/canvas@v1.1.1/explicit_lifecycle.ts'
// we choose when to begin the slow load
await Canvas.load()
const canvas = Canvas.MakeCanvas(200, 200);
// do some stuff with the canvas...
// we choose when to perform cleanup
await Canvas.unload()
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
Very Long delay before starting actual execution of a unit test ...
I am observing a delay of around 2.5 mins to start actual execution of the test script on my machine. Instead if i...
Read more >Logon scripts don't run for five minutes - Windows Client
However, the default behavior of a Group Policy client is to wait five minutes before it runs logon scripts. The goal of the...
Read more >DataStage sequence job has long delay after regaining ... - IBM
For one specific DataStage sequence job, after it calls an external script to perform tasks with OS files, there is an hours-long delay...
Read more >Adding a Delay to a Script - Ignition User Manual 7.9
One approach to this is to trigger our script, and then hold or wait until the other event occurs.
Read more >Delayed execution startup script - ASP.NET Community Blogs
Or, this is useful not only for a delay, but also to allow the windows startup to complete while a long running script...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Also found a fix! But kinda hacky. Reduced the decoding overhead from 2.8s to 0.5s by using internal op_base64_decode instead of std’s base64 decode which is pure js.
Most of the time as noticed in your benchmarks was taken by base64 decoding, at startup. WASM instantiation takes like 0.6s IIRC. Not sure about “after script execution”, but I suppose that might be background cleanup done for wasm at end by v8 or something.