rustfix icon indicating copy to clipboard operation
rustfix copied to clipboard

Performance: Use SmallVec in rustfix

Open deeprobin opened this issue 3 years ago • 0 comments

I suggest using SmallVec (smallvec crate) instead of a regular Vec to improve performance, by having a SmallVec allocate primarily on the stack and the heap is secondary.

Where this could be useful

  • https://github.com/rust-lang/rustfix/blob/ae9b64599c43a49a164ab8b4d0eb9947fd2ab117/src/lib.rs#L28-L29
  • https://github.com/rust-lang/rustfix/blob/ae9b64599c43a49a164ab8b4d0eb9947fd2ab117/src/lib.rs#L65-L66
  • https://github.com/rust-lang/rustfix/blob/ae9b64599c43a49a164ab8b4d0eb9947fd2ab117/src/lib.rs#L72
  • https://github.com/rust-lang/rustfix/blob/ae9b64599c43a49a164ab8b4d0eb9947fd2ab117/src/replace.rs#L33-L34
  • https://github.com/rust-lang/rustfix/blob/ae9b64599c43a49a164ab8b4d0eb9947fd2ab117/src/lib.rs#L107
  • https://github.com/rust-lang/rustfix/blob/ae9b64599c43a49a164ab8b4d0eb9947fd2ab117/src/lib.rs#L131
  • https://github.com/rust-lang/rustfix/blob/ae9b64599c43a49a164ab8b4d0eb9947fd2ab117/src/lib.rs#L191
  • https://github.com/rust-lang/rustfix/blob/ae9b64599c43a49a164ab8b4d0eb9947fd2ab117/src/replace.rs#L163

Of course, it doesn't make sense to blindly replace something like that, but you could analyze this with benchmarks to see where a SmallVec would make sense.

Additional/useful resources

deeprobin avatar May 19 '21 12:05 deeprobin