High speed efficiency and performance. #561
Replies: 3 comments 1 reply
-
I'm not sure what you're suggesting that might be actionable.
|
Beta Was this translation helpful? Give feedback.
-
I am also using goja in a high performance environment and i came up with a solution which fits our needs. Our requirement is that we have to run Java-Script scripts in a repeatable fashion with different contexts attached to it. We do this highly concurrently. First of all you should wrap a single VM into a wrapper which would allow you to execute javascript throuh channels, this basically makes one engine thread safe. The next step is to create a pool of engines, say 50 and you loadbalance requests over this pooled VM. The final step is to pre-compile the scripts and cache them. You should then also always use strict mode which prevents global pollution. Here are some benchmarks of mine func benchmarkRoutines(b *testing.B, engine Engine, maxCompilations int) {
var wg sync.WaitGroup
wg.Add(b.N)
ctx := context.Background()
for i := 0; i < b.N; i++ {
go func(i int) {
v, err := engine.Run(ctx, `return 1 + 2 + k`, map[string]any{"k": i})
if err != nil {
b.Error(err)
return
} else {
assert.Equal(b, int64(3+i), v)
}
wg.Done()
}(i)
}
wg.Wait()
// There must be only a single compilation
if maxCompilations > 0 {
assert.Equal(b, uint64(maxCompilations), engine.ccount())
}
}
|
Beta Was this translation helpful? Give feedback.
-
@timo-klarshift Can you share the specific benchmark code, I would like to refer to it. |
Beta Was this translation helpful? Give feedback.
-
My understanding is that performance is better when
Are there any other performance notes anyone can provide for a high speed usage efficiency? Anything would be appreciated!
Thank you.
I did a profile of a go app using goja, Following is a 30 second profile:
Beta Was this translation helpful? Give feedback.
All reactions