Skip to content

Commit

Permalink
LSP Optimization: Add par_iters to the traverse::typed_tree module (#…
Browse files Browse the repository at this point in the history
…5487)

## Description

Use `rayon` par_iters in the `traverse::typed_tree` module. We are
already doing this in `traverse::parsed_tree`, this just brings this
over to the typed_tree module as well.

Branched off #5473. <s>Will want to merge that first then will take this
out of draft.</s>

Collecting typed tokens on the benchmark project goes from
`120.508917ms` → `14.853125ms`

related to #5445
  • Loading branch information
JoshuaBatty authored Jan 17, 2024
1 parent 63aa900 commit c5adaa6
Show file tree
Hide file tree
Showing 2 changed files with 178 additions and 128 deletions.
19 changes: 16 additions & 3 deletions sway-lsp/src/core/token_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,27 @@ impl<'a> TokenMap {
}

/// Attempts to get a mutable reference to a token with retries on lock.
/// Retries up to 10 times with increasing backoff (1ns, 10ns, 100ns, 500ns, 1µs, 10µs, 100µs, 1ms, 10ms, 50ms).
/// Retries up to 14 times with increasing backoff (1ns, 10ns, 100ns, 500ns, 1µs, 10µs, 100µs, 1ms, 10ms, 50ms, 100ms, 200ms, 500ms, 1s).
pub fn try_get_mut_with_retry(
&'a self,
ident: &TokenIdent,
) -> Option<RefMut<TokenIdent, Token>> {
const MAX_RETRIES: usize = 10;
const MAX_RETRIES: usize = 14;
let backoff_times = [
1, 10, 100, 500, 1_000, 10_000, 100_000, 1_000_000, 10_000_000, 50_000_000,
1,
10,
100,
500,
1_000,
10_000,
100_000,
1_000_000,
10_000_000,
50_000_000,
100_000_000,
200_000_000,
500_000_000,
1_000_000_000,
]; // Backoff times in nanoseconds
for (i, sleep) in backoff_times.iter().enumerate().take(MAX_RETRIES) {
match self.try_get_mut(ident) {
Expand Down
Loading

0 comments on commit c5adaa6

Please sign in to comment.