Last active
October 21, 2021 18:25
-
-
Save genevieve/819b1a68c1ec61a3e668fe5b738ceaa4 to your computer and use it in GitHub Desktop.
v8 isolates sharing compiled scripts / cached data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"time" | |
v8 "rogchap.com/v8go" | |
) | |
func main() { | |
s := "function foo() { return 'bar'; }; foo()" | |
for i := 0; i < 10; i++ { | |
iso := v8.NewIsolate() | |
ctx := v8.NewContext(iso) | |
start := time.Now() | |
ctx.RunScript(s, "script.js") | |
fmt.Printf("RunScript in iso %d: %s\n", i, time.Since(start)) | |
ctx.Close() | |
iso.Dispose() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
go run main.go | |
RunScript in iso 0: 328.929µs | |
RunScript in iso 1: 55.516µs | |
RunScript in iso 2: 53.565µs | |
RunScript in iso 3: 59.998µs | |
RunScript in iso 4: 76.415µs | |
RunScript in iso 5: 49.581µs | |
RunScript in iso 6: 50.965µs | |
RunScript in iso 7: 51.065µs | |
RunScript in iso 8: 48.945µs | |
RunScript in iso 9: 65.047µs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment