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

Experimental: JS compression via Closure Compiler #20967

Draft
wants to merge 24 commits into
base: 5.x-dev
Choose a base branch
from

Conversation

rr-it
Copy link
Contributor

@rr-it rr-it commented Jul 5, 2023

Description:

Experimental: This introduces JS compression of piwik.js via Closure Compiler.

See #20964

Review

rr-it added 19 commits July 7, 2023 13:10
```
var i = 0;
for (i; i < object.length; i++) {}
```

becomes

```
var i;
for (i = 0; i < object.length; i++) {}
```

Alternative (unreadable):

```
var i = 0;
for (; i < object.length; i++) {}
```
…mpiler

This disables type warnings: `JSC_UNRECOGNIZED_TYPE_ERROR`, `JSC_TYPE_MISMATCH`, `JSC_WRONG_ARGUMENT_COUNT` and more.
…for `piwik.js`

+ Copy all functions that begin with `this.nameOfFunction` from `function Tracker()` in `piwik.js`. Exclude functions inside `/*<DEBUG>*/ … /*</DEBUG>*/`-markers.
+ Rename inside `piwik.externs.js` via find `^this\.` and replace by `Tracker.`
+ Empty method bodies inside `piwik.externs.js` via find `\{(\n .+|\n)+\n\};` and replace by `{};`
…o exclude them from Closure Compiler munging
@rr-it rr-it force-pushed the issue/20964-experimental-closure-compiler branch from 603676d to 542bd46 Compare July 7, 2023 11:10
@bx80
Copy link
Contributor

bx80 commented Jul 10, 2023

Thanks for this analysis and contribution @rr-it, it's much appreciated 👍 We'll review this PR and schedule some testing.

A ~20% decrease in tracking code size sounds great, even if only a few kilobyte, it can soon add up to a useful traffic reduction when serving many millions of requests per month.

…ct in quotes to exclude them from Closure Compiler munging
Some common JS names defined in the default Closure Compiler `externs` are not munged e.g.:
location, name, target, type, href, enabled, timeout, interval

When renamed by prepending with an underscore they get correctly munged.
Some common JS names defined in the default Closure Compiler `externs` are not munged:
find, push, trim

When renamed the functions and calls get correctly munged.
@github-actions
Copy link
Contributor

If you don't want this PR to be closed automatically in 28 days then you need to assign the label 'Do not close'.

@github-actions github-actions bot added the Stale The label used by the Close Stale Issues action label Jul 27, 2023
@michalkleiner michalkleiner removed the Stale The label used by the Close Stale Issues action label Jul 27, 2023
@github-actions
Copy link
Contributor

If you don't want this PR to be closed automatically in 28 days then you need to assign the label 'Do not close'.

@github-actions github-actions bot added the Stale The label used by the Close Stale Issues action label Aug 11, 2023
@michalkleiner michalkleiner added Do not close PRs with this label won't be marked as stale by the Close Stale Issues action and removed Stale The label used by the Close Stale Issues action labels Aug 15, 2023
@mattab mattab added c: Performance For when we could improve the performance / speed of Matomo. c: Tracking For issues related to getting tracking data into Matomo. labels Dec 11, 2023
@mattab mattab added this to the 5.x.0 - Priority issues milestone Dec 11, 2023
@mattab mattab added the Technical debt Issues the will help to reduce technical debt label Dec 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: Performance For when we could improve the performance / speed of Matomo. c: Tracking For issues related to getting tracking data into Matomo. Do not close PRs with this label won't be marked as stale by the Close Stale Issues action Technical debt Issues the will help to reduce technical debt
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants