Skip to content

Conversation

@Dosant
Copy link
Contributor

@Dosant Dosant commented Jul 30, 2021

Summary

Partially addresses #107280:

Do not use Buffer in client-side data and bfetch code to reduce bundle size
Also, fix a single lodash import in data

Alternatively, this Buffer polyfill should be shared across bundles since it is anyway used in core

*/

import { unzlibSync, strFromU8 } from 'fflate';
import { toByteArray } from 'base64-js';
Copy link
Contributor Author

@Dosant Dosant Jul 30, 2021

Choose a reason for hiding this comment

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

This is an existing dependency and it's a dependency of Buffer polyfill. So using it directly here doesn't make it worse. It costs less than the whole Buffer

* Side Public License, v 1.
*/

import escape from 'lodash/escape';
Copy link
Contributor Author

@Dosant Dosant Jul 30, 2021

Choose a reason for hiding this comment

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

Fixing wrong import. Should be better now, because lodash is included in shared deps

return Buffer.from(val, 'base64').toString('utf8');
if (window && window.atob) return window.atob(val);
// referencing from `global` tricks webpack to not include `Buffer` polyfill into this bundle
return global.Buffer.from(val, 'base64').toString('utf8');
Copy link
Contributor Author

@Dosant Dosant Jul 30, 2021

Choose a reason for hiding this comment

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

This seems to be tricking webpack to not bundle a polyfill for Buffer

@Dosant
Copy link
Contributor Author

Dosant commented Jul 30, 2021

@elasticmachine merge upstream

@Dosant Dosant changed the title lower bundle size [data][bfetch] Avoid using Buffer in client code Jul 30, 2021
@Dosant Dosant added release_note:skip Skip the PR/issue when compiling release notes Team:AppServices v7.15.0 v8.0.0 auto-backport Deprecated - use backport:version if exact versions are needed labels Jul 30, 2021
@Dosant Dosant marked this pull request as ready for review July 30, 2021 16:59
@Dosant Dosant requested review from a team as code owners July 30, 2021 16:59
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app-services (Team:AppServices)

Copy link
Contributor

@lizozom lizozom left a comment

Choose a reason for hiding this comment

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

Beautiful changes. Thank you!

@botelastic botelastic bot added the Feature:ExpressionLanguage Interpreter expression language (aka canvas pipeline) label Jul 31, 2021
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
bfetch 29 25 -4
data 615 596 -19
total -23

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
bfetch 46.9KB 16.0KB -30.9KB
data 907.1KB 870.7KB -36.3KB
total -67.3KB

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Member

@mistic mistic left a comment

Choose a reason for hiding this comment

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

LGTM

@Dosant Dosant merged commit 0c69b10 into elastic:master Aug 2, 2021
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Aug 2, 2021
@kibanamachine
Copy link
Contributor

💚 Backport successful

Status Branch Result
7.x

This backport PR will be merged automatically after passing CI.

kibanamachine added a commit that referenced this pull request Aug 2, 2021
Co-authored-by: Anton Dosov <anton.dosov@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-backport Deprecated - use backport:version if exact versions are needed Feature:ExpressionLanguage Interpreter expression language (aka canvas pipeline) release_note:skip Skip the PR/issue when compiling release notes v7.15.0 v8.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants