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

chore: formatter caching #1700

Merged
merged 7 commits into from
Mar 3, 2025
Merged

chore: formatter caching #1700

merged 7 commits into from
Mar 3, 2025

Conversation

tippenein
Copy link
Collaborator

@tippenein tippenein commented Feb 27, 2025

simple caching to speed up benchmarks

formatter                     fastest       │ slowest       │ median        │ mean          │ samples │ iters
╰─ format_benches                           │               │               │               │         │
   ├─ format_all_contracts    34.29 ms      │ 43.32 ms      │ 34.52 ms      │ 35.38 ms      │ 10      │ 10
   ├─ format_clarity_bitcoin  8.751 ms      │ 10.11 ms      │ 9.931 ms      │ 9.846 ms      │ 10      │ 10
   ╰─ format_heavy_section    2.221 ms      │ 2.221 ms      │ 2.221 ms      │ 2.221 ms      │ 1       │ 1

Main changes:

  • use slice::from_ref when passing exprs into recursion
  • cache using the pointer to that expr or list of exprs (display_pse and format_source_exprs)

@tippenein tippenein changed the title formatter caching chore: formatter caching Feb 27, 2025
@tippenein tippenein marked this pull request as draft February 27, 2025 20:37
@tippenein tippenein marked this pull request as ready for review February 28, 2025 07:34
Copy link

codecov bot commented Feb 28, 2025

Codecov Report

Attention: Patch coverage is 96.51163% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
components/clarinet-format/src/formatter/mod.rs 96.51% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Collaborator

@hugocaillard hugocaillard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work on the perf 🙌

I'm wondering if the CACHEs need to be top level RefCell?
Could it be stored in the Aggregator directly?

pub struct Aggregator {
    ...,
   expr_cache: HashMap<(usize, String),
   list_cache: HashMap<(usize, String),
}

Or what are benefits with the refcell approach here?

@tippenein
Copy link
Collaborator Author

@hugocaillard simplified the cache a bit. Also removed the redundant segment of raw source from clarity-bitcoin since we already test that.

@tippenein tippenein enabled auto-merge (squash) February 28, 2025 20:34
Copy link
Collaborator

@hugocaillard hugocaillard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm ⚡

@tippenein tippenein merged commit 329174e into main Mar 3, 2025
25 checks passed
@tippenein tippenein deleted the cached-format-exprs branch March 3, 2025 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants