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
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions components/clarinet-format/benches/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,25 @@ mod format_benches {

bencher.bench_local(|| black_box(formatter.format(black_box(&source))));
}

#[divan::bench(sample_count = 1)]
fn format_heavy_section(bencher: Bencher) {
let formatter = ClarityFormatter::new(Settings::default());
let source = r#"(define-read-only (parse-wtx (tx (buff 4096)) (calculate-txid bool))
(begin
(ok {
txid: (if calculate-txid
(some (reverse-buff32 (sha256 (sha256
(concat
(unwrap-panic (slice? tx u0 u4))
(concat
(unwrap-panic (slice? tx (get index (get ctx parsed-segwit-version)) (get index (get ctx parsed-txouts))))
(unwrap-panic (slice? tx (get index (get ctx parsed-witnesses)) (len tx)))))))))
none)
})
))"#;
bencher.bench_local(|| black_box(formatter.format(black_box(source))));
}
}

fn main() {
Expand Down
12 changes: 0 additions & 12 deletions components/clarinet-format/src/formatter/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use clarity::vm::representations::PreSymbolicExpression;

/// trim but leaves newlines preserved
pub fn t(input: &str) -> &str {
let start = input
Expand All @@ -13,13 +11,3 @@ pub fn t(input: &str) -> &str {

&input[start..end]
}
/// REMOVE: just grabs the 1st and rest from a PSE
pub fn name_and_args(
exprs: &[PreSymbolicExpression],
) -> Option<(&PreSymbolicExpression, &[PreSymbolicExpression])> {
if exprs.len() >= 2 {
Some((&exprs[1], &exprs[2..]))
} else {
None // Return None if there aren't enough items
}
}
Loading
Loading