# GeneralPurposeAllocator.searchBucket: check current bucket before searching the list · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/ec0f76c5996e88f61d376640bf36ed7feb2b0ea6)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: ec0f76c5996e88f61d376640bf36ed7feb2b0ea6

Requested commit: ec0f76c5996e88f61d376640bf36ed7feb2b0ea6

Commit: ec0f76c5996e88f61d376640bf36ed7feb2b0ea6

Tree: 1f8ca77b728ca1381fb40615c2eff9817945ff6f

Author: Ryan Liptak

Committer: Andrew Kelley

## Message

```
GeneralPurposeAllocator.searchBucket: check current bucket before searching the list

Follow up to #17383. This is a minor optimization that only matters when a small allocation is resized/free'd soon after it is allocated.

The only real difference I was able to observe with this was via a synthetic benchmark that allocates a full bucket and then frees all but one of the slots, over and over in a loop:

Debug build:

Benchmark 1 (9 runs): gpa-degen-master.exe
  measurement          mean ± σ            min … max           outliers         delta
  wall_time           575ms ± 5.19ms     569ms …  583ms          0 ( 0%)        0%
  peak_rss           43.8MB ± 1.37KB    43.8MB … 43.8MB          1 (11%)        0%
Benchmark 2 (10 runs): gpa-degen-search-cur.exe
  measurement          mean ± σ            min … max           outliers         delta
  wall_time           532ms ± 5.55ms     520ms …  539ms          0 ( 0%)        ⚡-  7.5% ±  0.9%
  peak_rss           43.8MB ± 65.2KB    43.8MB … 44.0MB          1 (10%)          +  0.0% ±  0.1%

ReleaseFast build:

Benchmark 1 (129 runs): gpa-degen-master-release.exe
  measurement          mean ± σ            min … max           outliers         delta
  wall_time          38.9ms ± 1.12ms    36.7ms … 42.4ms          8 ( 6%)        0%
  peak_rss           23.2MB ± 2.39KB    23.2MB … 23.2MB          0 ( 0%)        0%
Benchmark 2 (151 runs): gpa-degen-search-cur-release.exe
  measurement          mean ± σ            min … max           outliers         delta
  wall_time          33.2ms ±  999us    31.9ms … 36.3ms         20 (13%)        ⚡- 14.7% ±  0.6%
  peak_rss           23.2MB ± 2.26KB    23.2MB … 23.2MB          0 ( 0%)          +  0.0% ±  0.0%

```

## Parents

- [11489bb04f82cf91e23bd1980fb4cf49b5a6fc54](https://git.cafe/gitcafe/zig/commit/11489bb04f82cf91e23bd1980fb4cf49b5a6fc54?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/ec0f76c5996e88f61d376640bf36ed7feb2b0ea6?format=markdown)
