Skip to content

Commit

Permalink
Reuse the parsed core-js library across VUs
Browse files Browse the repository at this point in the history
  • Loading branch information
na-- committed Jun 3, 2019
1 parent 2999a1e commit 0dd4262
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
22 changes: 17 additions & 5 deletions js/lib/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,26 @@
package lib

import (
"sync"

"github.com/GeertJohan/go.rice"
"github.com/dop251/goja"
)

//nolint:gochecknoglobals
var (
once sync.Once
coreJs *goja.Program
)

func GetCoreJS() *goja.Program {
return goja.MustCompile(
"core-js/shim.min.js",
rice.MustFindBox("core-js").MustString("shim.min.js"),
true,
)
once.Do(func() {
coreJs = goja.MustCompile(
"core-js/shim.min.js",
rice.MustFindBox("core-js").MustString("shim.min.js"),
true,
)
})

return coreJs
}
4 changes: 4 additions & 0 deletions release notes/upcoming.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ Now all http methods have an additional param called `compression` that will mak
- windows: work with paths starting with `/` or `\` as absolute from the current drive

* JS: Correctly always set `response.url` to be the URL that was ultimately fetched (i.e. after any potential redirects), even if there were non http errors. (#990)

## Internals

* JS: VU initialization time and memory usage has been significantly decreased by caching the parsed version of the core-js library. Thanks, @matlockx! (#1038)

0 comments on commit 0dd4262

Please sign in to comment.