Rollup-plugin-typescript2: Cache makes bundling slower instead of faster in recent versions (starting with 0.19.0)?

Created on 15 Feb 2019  ·  6Comments  ·  Source: ezolenko/rollup-plugin-typescript2

It seems that the build cache of this plugin makes performance worse instead of improving it, starting with package version 0.19.0.

I noticed this when upgrading the build scripts at my company to use the latest package versions of everything; including an update of ezolenko/rollup-plugin-typescript2 from version 0.12.x to 0.19.2. This increased bundling times by a factor of approx. 2x (from approx. 3 sec. to 6-8 sec per bundling).

I thought I'd share my brief investigations with you. I set up a small benchmark (see stakx/rollup-plugin-typescript2-benchmark) to demonstrate this. Admittedly it's not a super-accurate benchmark, but I think it still shows that setting the clean option to false appears to affect bundling time negatively (instead of improving it, as one would expect from having a cache ready for use).

I'll reproduce the measurements I took below; see the linked repo for the actual benchmark code.

Package version | run | clean: true [ms] | clean: false [ms] | clean: false ÷ clean: true [%]
:-:|:-:|--:|--:|--:
0.15.0 | 1 | 836 | 670 |
| | 2 | 840 | 638 |
| | 3 | 884 | 574 |
| | avg. | 853 | 627 | 74 %
0.16.0 | 1 | 841 | 576 |
| | 2 | 816 | 607 |
| | 3 | 834 | 581 |
| | avg. | 830 | 588 | 71 %
0.17.0 | 1 | 861 | 582
| | 2 | 839 | 603
| | 3 | 835 | 594
| | avg. | 845 | 593 | 70 %
0.18.0 | 1 | 1147 | 998
| | 2 | 1192 | 882
| | 3 | 1207 | 882
| | avg. | 1182 | 921 | 78 %
0.18.1 | 1 | 815 | 617
| | 2 | 837 | 590
| | 3 | 823 | 590
| | avg. | 825 | 599 | 73 %
0.19.0 | 1 | 828 | 896
| | 2 | 803 | 897
| | 3 | 836 | 901
| | avg. | 822 | 898 | 109 %
0.19.1 | 1 | 850 | 913
| | 2 | 825 | 888
| | 3 | 799 | 881
| | avg. | 825 | 894 | 108 %
0.19.2 | 1 | 1020* | 888
| | 2 | 816 | 902
| | 3 | 826 | 890
| | avg. | 887 | 893 | 101 %

Note how having a cache populated (clean: false) led to quicker bundling times (approx. 70 % of clean: false) up until 0.18.1. Starting with 0.19.0, clean: false would actually increase bundling times by approx. 10 %. (Note also the outlier marked with a *, which makes 0.19.2 appear to perform better than it really does.)

This cache slowdown is quite a pity especially since clean: false is currently the default.

(P.S.: I'd like to make clear that I'm not saying clean: false will by itself be sufficient to worsen performance of this plugin. I simply noticed this and found it curious, it might be worth looking into more closely.)

bug

Most helpful comment

In 0.19.3 on npm now

All 6 comments

Thanks, I'll look at it sometime next week hopefully. In general I expect clean: true to be a bit faster than the first run with cache, and significantly slower than the second run with cache. Looks like you are comparing first runs on clean system?

Another variable to control is typescript and rollup version.

There was a fix, forgot in which version, that removed cache creation entirely when clean: true was used, so less work was being done during the build.

Btw, that probably means build machines that do a clean checkout (which every sane non CI deployment configuration should be doing) might see a bit of speed up by disabling cache.

Looks like you are comparing first runs on clean system?

My benchmark performs two runs:

  • The first one runs after the cache has been manually wiped using rimraf. This run doesn't get measured, it's just there to build a fresh cache.

  • The second run (which could take advantage of a fresh cache if clean: false) is the one that gets measured.

Ok, I see it. Looks like in 19.2 cache is always missed for some reason.

Ok fixed in master. I still have to check how the fix affects watch mode though.

In 0.19.3 on npm now

Awesome! Thank you for taking care of this so promptly. Great to see a project being maintained so well. :+1:

Was this page helpful?
0 / 5 - 0 ratings