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

Two-phase serialization #426

Open
overlookmotel opened this issue Sep 25, 2022 · 1 comment
Open

Two-phase serialization #426

overlookmotel opened this issue Sep 25, 2022 · 1 comment
Labels
enhancement Improvements

Comments

@overlookmotel
Copy link
Owner

overlookmotel commented Sep 25, 2022

Initially discussed in #169 (comment)

What

Serialization should be broken up into 2 phases:

1. Trace: Construct a "program graph"

"Program graph" is similar to an "abstract syntax tree" (AST), except it represents values, rather than code syntax. "Tracing" is analogous to the "parse" phase of Babel.

In this phase, every value referenced within the program is converted to a "record" representing its type, properties, and dependencies ("record" is analogous to an AST "node").

The entire graph of dependencies (properties of objects, scope of functions) are traced from program entry point (tree root), recursively, until all values reachable by the program are visited and added to the graph.

Unlike an AST, a program graph may be cyclic, and each record may have multiple dependencies and dependents upon other records.

2. Serialize

The serialize phase takes the program graph and converts to a JS AST, which is then printed as JS code.

Why

Currently tracing and serialization are performed together in a single pass.

Splitting the process into 2 phases would:

  1. Allow tracing in any order, which enables various optimizations
  2. Make Livepack's codebase more readable
  3. Allow plugins to alter the program graph between the two phases: (similar to how Babel plugins transform the AST)

Progress

Some initial work on two-phase branch.

@overlookmotel
Copy link
Owner Author

Most recent iteration of implementation on two-phase3 branch.

This implementation covers almost everything except functions and code splitting (the hardest parts!).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvements
Projects
None yet
Development

No branches or pull requests

1 participant