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

Unnecessary injection into scope where functions refer to other functions in same block but not same scope #227

Open
overlookmotel opened this issue Jul 19, 2021 · 2 comments
Labels
optimization Improvement to performance or output

Comments

@overlookmotel
Copy link
Owner

Input:

function outer(ext) {
  let other = (0, () => ext);
  const inner = (0, () => other);
  const setOther = v => other = v;
  return { inner, other, setOther };
}

const { inner, setOther } = outer(1);
const { other } = outer(2);
setOther(other);
export default inner;

Output:

const createScopeOuter = (other, ext) => [
    _other => other = _other,
    () => ext,
    () => other
  ],
  scopeOuter = createScopeOuter();
scopeOuter[0]( createScopeOuter(void 0, 2)[1] );
export default scopeOuter[2];

other from 2nd scope is injected into first scope. This is unnecessary. Output could be shorter:

const createScopeOuter = (other, ext) => [
    () => ext,
    () => other
  ];
export default createScopeOuter( createScopeOuter(void 0, 2)[0] )[1];

This inefficient output is caused by a4c86d7 which was solution to #226.

@overlookmotel overlookmotel added the optimization Improvement to performance or output label Jul 19, 2021
@overlookmotel
Copy link
Owner Author

overlookmotel commented Jul 19, 2021

Fixing this would require a complicated analysis to detect circularity.

Two-phase serialization (as discussed in #169 (comment)) would make these cases easier to identify.

@overlookmotel
Copy link
Owner Author

Two-phase serialization now has its own issue: #426

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
optimization Improvement to performance or output
Projects
None yet
Development

No branches or pull requests

1 participant