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

Implement Serde for AstNode types #6605

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft

Implement Serde for AstNode types #6605

wants to merge 4 commits into from

Conversation

JoshuaBatty
Copy link
Member

@JoshuaBatty JoshuaBatty commented Oct 4, 2024

Description

This PR extends Serde support across all AstNode-related types, building upon the partial implementation from #4193. Key points:

  • Adds both Serialize and Deserialize trait implementations to all relevant types.
  • Prepares for upcoming language server features that will serialize/deserialize types between keystrokes.
  • Important: The type interface in the compiler is not yet stable. This implementation is intended for temporary serialization/deserialization work, not for persistent storage.

Checklist

  • I have linked to any relevant issues.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation where relevant (API docs, the reference, and the Sway book).
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added (or requested a maintainer to add) the necessary Breaking* or New Feature labels where relevant.
  • I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • I have requested a review from the relevant team or maintainers.

@JoshuaBatty JoshuaBatty marked this pull request as draft October 4, 2024 01:35
@JoshuaBatty JoshuaBatty self-assigned this Oct 4, 2024
@JoshuaBatty JoshuaBatty added the compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen label Oct 4, 2024
Copy link

codspeed-hq bot commented Oct 4, 2024

CodSpeed Performance Report

Merging #6605 will improve performances by 21%

Comparing josh/serde (9864851) with master (d399580)

Summary

⚡ 1 improvements
✅ 21 untouched benchmarks

Benchmarks breakdown

Benchmark master josh/serde Change
format 453.3 ms 374.6 ms +21%

@tritao
Copy link
Contributor

tritao commented Oct 4, 2024

  • Prepares for upcoming language server features that will serialize/deserialize types between keystrokes.

Could you maybe expand a bit on how this will work?

@JoshuaBatty
Copy link
Member Author

  • Prepares for upcoming language server features that will serialize/deserialize types between keystrokes.

Could you maybe expand a bit on how this will work?

Hey @tritao sorry for the delay, just getting back to this work now. So the motivation for this was noticing really high RAM usage in the language server now. For example, just running the counter example we can see 800mb of heap memory is never deallocated after the first compilation pass.

On digging it seems this is due to the new module caching where we hold onto the types themselves, thus never allow Drop to be called.

#[derive(Clone, Debug)]
pub struct TypedModuleInfo {
    pub module: Arc<TyModule>,
    pub version: Option<u64>,
}

My motivation was to Serialize these types using postcard (same that is used in fuel-core) and then store the Serialize version in the module cache. We then need to Deserialize back into the original type on each keystroke which will incur some performance overhead but I haven't got any measurements yet, was going to tackle that in an up coming PR. WDYT, are you happy with the approach or do you think there is a better solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants