From 0dd426233d17d24238d3a439eeed802ef41edd86 Mon Sep 17 00:00:00 2001 From: Nedyalko Andreev Date: Mon, 3 Jun 2019 11:50:37 +0300 Subject: [PATCH] Reuse the parsed core-js library across VUs --- js/lib/lib.go | 22 +++++++++++++++++----- release notes/upcoming.md | 4 ++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/js/lib/lib.go b/js/lib/lib.go index 4d350dea818..f3c6adad30f 100644 --- a/js/lib/lib.go +++ b/js/lib/lib.go @@ -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 } diff --git a/release notes/upcoming.md b/release notes/upcoming.md index bb1607bee23..76edc368d20 100644 --- a/release notes/upcoming.md +++ b/release notes/upcoming.md @@ -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) \ No newline at end of file