Skip to content

Remove input and length from state#9646

Merged
danez merged 1 commit intobabel:masterfrom
danez:move-input
Mar 11, 2019
Merged

Remove input and length from state#9646
danez merged 1 commit intobabel:masterfrom
danez:move-input

Conversation

@danez
Copy link
Member

@danez danez commented Mar 7, 2019

Q                       A
Fixed Issues?
Patch: Bug Fix? n
Major: Breaking Change? n
Minor: New Feature? n
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

In #9348 I moved input into the state because it was in both state and directly in the parser. I wanted to make things easier and only have it stored once.
Looking at it now, this was a bad decision. Why? Because everything in the state is variable and changes over time, besides input. Even worse state gets cloned in several locations, which means the (potential big) string in input will get copied around for no reason. I'm not sure how v8 handles this things, but afaik in javascript assigning primitives to a new variable/property copies the value.

This reverses it and moves the input (+ its length) to the parser only.
I couldn't spot a visible performance change with this, but also haven't checked the memory footprint.

@danez danez added PR: Polish 💅 A type of pull request used for our changelog categories pkg: parser labels Mar 7, 2019
@babel-bot
Copy link
Collaborator

babel-bot commented Mar 7, 2019

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/10422/

Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

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

I don't know how it works from a memory pow, but "it does never change" is enough for me to remove it from State.

@danez danez merged commit cf4bd8b into babel:master Mar 11, 2019
@danez danez deleted the move-input branch March 11, 2019 07:42
@danez
Copy link
Member Author

danez commented Mar 11, 2019

I created a memory benchmark and according to it, the memory usage does not change much:

~/Documents/Github/babylon_performance master* 8s
❯ node --expose-gc --max-old-space-size=2000 --max-semi-space-size=1500 --noconcurrent_sweeping mem.js
Node: v10.15.1
Running benchmark for ember.debug.js ...
Running benchmark for jquery.js ...
Running benchmark for angular.js ...
Running benchmark for babylon-dist.js ...
Running benchmark for backbone.js ...
Running benchmark for react-with-addons.js ...
┌──────────────────────┬──────────────────────┬───────────────────────┐
│ fixture              │ babelInputInState x5 │ babelInputInParser x5 │
├──────────────────────┼──────────────────────┼───────────────────────┤
│ ember.debug.js       │ heap: 45.73 MiB      │ heap: 43.7 MiB        │
├──────────────────────┼──────────────────────┼───────────────────────┤
│ jquery.js            │ heap: 66.26 MiB      │ heap: 66.03 MiB       │
├──────────────────────┼──────────────────────┼───────────────────────┤
│ angular.js           │ heap: 130.01 MiB     │ heap: 129.72 MiB      │
├──────────────────────┼──────────────────────┼───────────────────────┤
│ babylon-dist.js      │ heap: 80.69 MiB      │ heap: 80.69 MiB       │
├──────────────────────┼──────────────────────┼───────────────────────┤
│ backbone.js          │ heap: 15.74 MiB      │ heap: 15.71 MiB       │
├──────────────────────┼──────────────────────┼───────────────────────┤
│ react-with-addons.js │ heap: 136.23 MiB     │ heap: 136.09 MiB      │
└──────────────────────┴──────────────────────┴───────────────────────┘

babel/parser_performance@4175d3c

mAAdhaTTah added a commit to mAAdhaTTah/babel that referenced this pull request Mar 15, 2019
* master: (58 commits)
  Remove dependency on home-or-tmp package (babel#9678)
  [proposal-object-rest-spread] fix templateLiteral in extractNormalizedKeys (babel#9628)
  Partial application plugin (babel#9474)
  Private Static Class Methods (Stage 3) (babel#9446)
  gulp-uglify@3.0.2
  rollup@1.6.0
  eslint@5.15.1
  jest@24.5.0
  regexpu-core@4.5.4
  Remove input and length from state (babel#9646)
  Switch from rollup-stream to rollup and update deps (babel#9640)
  System modules - Hoist classes like other variables (babel#9639)
  fix: Don't transpile ES2018 symbol properties (babel#9650)
  Add WarningsToErrorsPlugin to webpack to avoid missing build problems on CI (babel#9647)
  Update regexpu-core dependency (babel#9642)
  Add placeholders support to @babel/types and @babel/generator (babel#9542)
  Generate plugins file
  Make babel-standalone an ESModule and enable flow (babel#9025)
  Reorganize token types and use a map for them (babel#9645)
  [TS] Allow context type annotation on getters/setters (babel#9641)
  ...
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 4, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser PR: Polish 💅 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants