Skip to content

optim: add assumptions to Babel config, mirroring previous config #79

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

Merged
merged 1 commit into from
May 18, 2022

Conversation

agilgur5
Copy link
Owner

Summary

Optimize output by adding assumptions to the Babel config, which mirrors the previous build system's config that uses Babel 7.

Details

History

I knew the output was different (and larger) due to spec-compliancy changes, but somehow didn't think about adding loose etc as an optimization until I saw Babel's assumptions RFC. I thought I wrote about the output differences in #42 (review) , but I guess I didn't? Couldn't find it in a commit message either, but could've sworn I wrote it down somewhere...

- previously used Babel 6's preset-stage-2, which, in Babel 7, is the
  equivalent of turning on `loose` in `proposal-class-properties`:
  https://github.com/babel/babel/tree/v7.5.5/packages/babel-preset-stage-2

- top-level `assumptions` replace the old `loose` configurations:
  https://github.com/babel/rfcs/blob/main/rfcs/0003-top-level-assumptions.md#assumptions-list

- this makes the minified UMD size ~20% smaller, very close to the size
  it was previously w/ Babel 6
  - basically the size increase was, in part, due to added
    spec-compliancy cases
    - and we don't actually need that stricter spec-compliancy in this
      codebase's small usage, so we can add "assumptions" to have the
      compiler optimize more by skipping some checks / edge cases that
      are unnecessary in this case

- as a double-check measure, I compared the old package's minified UMD
  to see if it had the helpers in it
  - this was a bit hard to do as it was minified after all, but I was
    able to more-or-less correlate all the helpers with either error
    messages in the helper code (which can't be minified), or specific
    methods or properties that aren't normally touched (e.g.
    `enumerable`)
    - prev minified UMD: https://unpkg.com/react-signature-canvas@1.0.5/build/index.js
    - Babel helper code: https://github.com/babel/babel/blob/a24c1d047e6db77c32d9505c6876897b4c3689d2/packages/babel-helpers/src/helpers.ts#L207

  - this looks be a good bit closer to the old build's results, but
    should still be wary of possible legacy compat issues and note that
    in the release notes
    - in particular, the implicit update to `compat-table` that happened
      during upgrading of the build system, which would change what
      `defaults` means for `browserslist` etc
@agilgur5 agilgur5 added the kind: optimization Performance, space, size, etc improvement label May 18, 2022
Copy link
Owner Author

@agilgur5 agilgur5 left a comment

Choose a reason for hiding this comment

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

LGTM. Tiny change. Tests pass, and I double-checked that the example still works when using the UMD build too

@codecov

This comment was marked as resolved.

@agilgur5 agilgur5 merged commit bcf3c3f into main May 18, 2022
@agilgur5 agilgur5 deleted the optim-loose-assumptions-babel-7 branch May 18, 2022 01:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: optimization Performance, space, size, etc improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant