FuelLabs / FuelLabs/sway

Remove interior mutability in the ConcurrentSlab

Open
#6,180 2 comments 0 reactions 0 assignees View on GitHub
compiler: frontend performance team:compiler
Dominant language
Rust
Stars
61.4k
Forks
5.4k
Avg merge
3h 33m
Merged PRs (30d)
4

Description

Currently the `ConcurrentSlab` has an `RwLock`. As we don't do any concurrent processing in the compiler we should remove interior mutability. When profiling, the compiler seems to be spending ~80% of it's time on atomic operations around this type. Removing this should lead to a significant performance boost.

```rust
pub(crate) struct ConcurrentSlab {
pub inner: RwLock>,
}

pub fn insert(&self, value: T) -> usize {
self.insert_arc(Arc::new(value))
}
```

This should be changed to remove the `RwLock` and methods that mutate state should take `&mut self`.

```rust
pub(crate) struct ConcurrentSlab {
pub inner: Inner,
}

// change these methods to take &mut self
pub fn insert(&mut self, value: T) -> usize {
self.insert_arc(Arc::new(value))
}
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by locating the ConcurrentSlab definition and all callers of its mutating methods. Review how those callers hold and pass the slab, then remove the RwLock and update mutation to use &mut self; the compiler should build and its existing tests should pass without interior mutability.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.