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

FR: Further opportunities to DCE unused object methods #1097

Open
samouri opened this issue Oct 26, 2021 · 1 comment
Open

FR: Further opportunities to DCE unused object methods #1097

samouri opened this issue Oct 26, 2021 · 1 comment
Labels
compress Issue in the compression step suboptimal-output

Comments

@samouri
Copy link

samouri commented Oct 26, 2021

summary

Today I ran into a few surprising behaviors that I believe could be optimized.
I've figured out workarounds for them, but figured it would be good to post them here in case folks were interested in fixing them.

happy case: regular object properties

qux is unused and DCE'd.

const Foo = {
  bar: () => console.log('bar'),
  qux: () => console.log('qux'),
}

Foo.bar();

object methods

qux is unused yet retained.

const Foo = {
  bar() { console.log('bar')}
  qux() { console.log('qux')}
}

Foo.bar();

self-referencing object

qux is unused yet retained.

const Foo = {
  bar: () => console.log('bar'),
  qux: () => Foo.bar(),
}

Foo.bar();

function literal vs. reference

optimally optimized

function bar() { console.log('bar') }
const Foo = { bar: () => bar() }
Foo.bar();

deopted

function bar() { console.log('bar') }
const Foo = { bar }
Foo.bar();
@jridgewell
Copy link
Collaborator

I'm going to split this into two bugs: One for supporting DCE of object methods, and one for supporting self-referencing objects in DCE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compress Issue in the compression step suboptimal-output
Projects
None yet
Development

No branches or pull requests

2 participants