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

Shorten output for circular references #182

Open
overlookmotel opened this issue May 5, 2021 · 3 comments
Open

Shorten output for circular references #182

overlookmotel opened this issue May 5, 2021 · 3 comments
Labels
optimization Improvement to performance or output

Comments

@overlookmotel
Copy link
Owner

Input:

const x = {};
x.y = {x};
module.exports = x;

Current output:

const y = {},
  x = {y};
y.x = x;
module.exports = x;

This output is longer than it needs to be. It's several bytes longer than the input.

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

Same for deeper nesting e.g.:

const x = {};
x.y = {z: {x}};
module.exports = x;

@overlookmotel
Copy link
Owner Author

Possible implementation:

  • Serialization functions return both a node object and a Set of records of circular dependencies.
  • If the parent finds itself in that set of circular dependencies, it creates a deferred assignment x.y =.
  • If not, it adds the set of circular dependencies to its own set of circular dependencies which it returns, to be handled by it's parent/ancestor.

This would also provide a solution to #75.

@overlookmotel
Copy link
Owner Author

This will be easier to solve once two-phase serialization is implemented (#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