Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speeding up tc39 tests through using a pool of Babels #1839

Merged
merged 3 commits into from
Jul 29, 2021
Merged

Conversation

mstoykov
Copy link
Contributor

@mstoykov mstoykov commented Feb 3, 2021

PoC pool of babels so transformation is less bottlenecked on them

this speeds up tc39 tests

It also has the nice benefit of dropping the babels once they are no
longer needed if you just run k6.

But a different approach is probably going to be needed as the js package
(for example) with -race takes upwards of 3x as much time.

@codecov-io
Copy link

Codecov Report

Merging #1839 (9c6f290) into master (c6dec36) will decrease coverage by 1.51%.
The diff coverage is 60.86%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1839      +/-   ##
==========================================
- Coverage   71.60%   70.09%   -1.52%     
==========================================
  Files         179      178       -1     
  Lines       13928    13936       +8     
==========================================
- Hits         9973     9768     -205     
- Misses       3323     3530     +207     
- Partials      632      638       +6     
Flag Coverage Δ
ubuntu ?
windows 70.09% <60.86%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
js/common/util.go 65.21% <ø> (ø)
js/compiler/compiler.go 73.33% <60.86%> (-3.14%) ⬇️
js/modules/k6/http/cookiejar.go 15.00% <0.00%> (-55.00%) ⬇️
lib/netext/tls.go 18.00% <0.00%> (-30.00%) ⬇️
lib/testutils/httpmultibin/httpmultibin.go 66.29% <0.00%> (-23.60%) ⬇️
js/modules/k6/http/request.go 59.21% <0.00%> (-20.93%) ⬇️
loader/readsource.go 65.38% <0.00%> (-19.24%) ⬇️
lib/netext/httpext/request.go 82.53% <0.00%> (-14.46%) ⬇️
js/modules/k6/http/http_url.go 75.00% <0.00%> (-12.50%) ⬇️
lib/netext/httpext/digest_transport.go 68.42% <0.00%> (-10.53%) ⬇️
... and 12 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c6dec36...a1a210a. Read the comment docs.

Copy link
Contributor

@imiric imiric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the performance hit for regular tests because the babel object is short-lived? According to the sync.Pool docs:

On the other hand, a free list maintained as part of a short-lived object is not a suitable use for a Pool, since the overhead does not amortize well in that scenario. It is more efficient to have such objects implement their own free list.

In any case, I vote 👎 for this as is, since the main test suite taking ~15m will be painful every time, whereas the current ~11m runtime of the TC39 suite is perfectly fine, especially since it runs only on js/* changes.

@codecov-commenter
Copy link

codecov-commenter commented Jul 2, 2021

Codecov Report

Merging #1839 (4f1c964) into master (aa1fd6a) will decrease coverage by 0.01%.
The diff coverage is 60.71%.

❗ Current head 4f1c964 differs from pull request most recent head 325dbd3. Consider uploading reports for the commit 325dbd3 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1839      +/-   ##
==========================================
- Coverage   72.11%   72.10%   -0.02%     
==========================================
  Files         180      180              
  Lines       14243    14256      +13     
==========================================
+ Hits        10272    10279       +7     
- Misses       3346     3351       +5     
- Partials      625      626       +1     
Flag Coverage Δ
ubuntu 72.01% <60.71%> (-0.04%) ⬇️
windows 71.74% <60.71%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
js/compiler/compiler.go 63.76% <60.71%> (-2.31%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update aa1fd6a...325dbd3. Read the comment docs.

@mstoykov mstoykov marked this pull request as ready for review July 21, 2021 07:43
@mstoykov mstoykov requested a review from imiric July 21, 2021 07:43
Copy link
Contributor

@imiric imiric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just some minor things.

Could you include some before/after comparisons in the PR description?

js/compiler/compiler.go Outdated Show resolved Hide resolved
Comment on lines 176 to 178
if err != nil { // TODO cache this?
return
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we need to cache it? Actually, is the err check and return here needed at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in practice ... it should never be an error, I am almost fine with panicking as if babel doesn't compile ... well there is nothing we can do anymore ;)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure you answered my question 😅 If Babel doesn't compile then this would only fail once, so what's the point of caching it and of the TODO? And since we check this err a few lines below this, I don't see the point of this additional check and return from this lambda.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OKay .. the whole if is ... kind of not needed as this whole thing is inside once.Do.

But the idea behind the caching is that k6 will execute this once.Do .. once and only the first call will actually set the err for it's execution, all other executions will block on the once.Do until finished and will return a nil globalBabelCode

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see, so as a way to prevent blocking other goroutines? I would at least explain that in the TODO, as it's unclear why right now. Though given this is such an unlikely edge case I would just remove the check and TODO.

js/compiler/compiler.go Outdated Show resolved Hide resolved
js/compiler/compiler.go Show resolved Hide resolved
@mstoykov mstoykov changed the title PoC Speeding up tests Speeding up tc39 tests through using a pool of Babels Jul 22, 2021
@mstoykov
Copy link
Contributor Author

I will squash to 3 commits:

  1. disable "async"
  2. the speedup through pool
  3. enable windows parallelism

when we agree it looks okay to merge ;)

@mstoykov
Copy link
Contributor Author

mstoykov commented Jul 26, 2021

I don't think I will be doing anything else for now apart from rewriting commits once I get some 👍 (edit: I had a commit not pushed 🤦 )

Here is a list of all the newly skipped tests with an explanation on how it was generated (in the comment)

Copy link
Contributor

@imiric imiric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM, but I'm wondering if the Compiler pooling could've been done in the tc39 package instead. I'm always wary of changes that are only useful for tests, especially in a core package like compiler.

Also nitpick, but I'd prefer deleting lines instead of commenting them out, unless they're temporary and you're sure we might need them back.

And I'd really appreciate a before/after run time comparison in the description :)

The words are `async`, `yield`, `generator` and `Generator`.

This does remove nearly 1k previously ran test that were totally
unsupported, some of which "passed" as they expected it will not run.
A lot of tc39 test need to compile and transpile the code of the test
before they can execute it. Babel *does* take significant amount of time
to transpile even small programs and having only one means that on
machines with 8 cores most of the time is being spent waiting for babel.

This can be used in other places at a later point - `k6/http` and some
`js` package libs are also mostly babel transpile dominated.

This speeds up the running of the test by around 4x on my machine. An
@mstoykov
Copy link
Contributor Author

I deleted the commented lines and did unexport one of the methods that doesn't need to be exported anymore, along rebasing stuff to three commits.

I did the compilerpool in tc39 but it will actually be useful in both some js test and k6/http where there are a bunch of es6 tests that are predominantly tc39 transpiling :(. But I would update them at a later point

Also .... literally all the current caching in that package even now is for testing as the normal k6 can only compile/transpile one file at a time and could've just initialized one babel of it's own ... but in tests it makes a big difference we don't initialize babel for each time we need it (the goja compiler is a lot less of a problem ;) )

@mstoykov mstoykov requested a review from imiric July 29, 2021 07:06
Copy link
Contributor

@imiric imiric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Looking at the tests from other PRs, this speeds up the TC39 tests by 2 minutes (8 vs 6m), and the others don't seem to be impacted and have similar run times. So the description should at least be updated to remove "all other tests suffer".

Nice work! 👏

@mstoykov
Copy link
Contributor Author

mstoykov commented Jul 29, 2021

OH ... I keep forgetting this.
The best time I had previously to this was 8m 30s and the dropping of some of the test got another 20s. But I also sometimes get 10minutes+. After all changes I am consistently under 4minutes and usually closer to 3minutes 10-20s

@mstoykov mstoykov merged commit a460e69 into master Jul 29, 2021
@mstoykov mstoykov deleted the speedingUpTests branch July 29, 2021 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants