# rope: Micro optimize the creation of masks \(\#41132\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/370d4ce2007fb6bdac2e12b7c706b97396394fec)

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

Visibility: public

Requested revision: 370d4ce2007fb6bdac2e12b7c706b97396394fec

Requested commit: 370d4ce2007fb6bdac2e12b7c706b97396394fec

Commit: 370d4ce2007fb6bdac2e12b7c706b97396394fec

Tree: 6b9ef8e526e47ce04a4630eaf20ef1e74c569e89

Author: Adam Richardson

Committer: GitHub

## Message

````
rope: Micro optimize the creation of masks (#41132)

Using compiler explorer I saw that the compiler wasn't clever enough to
optimise away the branches in the masking code. I thought the compiler
would have a better chance if we always branched, which [turned out to
be the case](https://godbolt.org/z/PM594Pz18).

Running the benchmarks the biggest benefit I saw was:
```
push/65536              time:   [2.9067 ms 2.9243 ms 2.9417 ms]
                        thrpt:  [21.246 MiB/s 21.373 MiB/s 21.502 MiB/s]
                 change:
                        time:   [-8.3452% -7.2617% -6.2009%] (p = 0.00 < 0.05)
                        thrpt:  [+6.6108% +7.8303% +9.1050%]
                        Performance has improved.
```
But I did also see some regressions:
```
slice/4096              time:   [66.195 µs 66.815 µs 67.448 µs]
                        thrpt:  [57.915 MiB/s 58.464 MiB/s 59.012 MiB/s]
                 change:
                        time:   [+3.7131% +5.1698% +6.6971%] (p = 0.00 < 0.05)
                        thrpt:  [-6.2768% -4.9157% -3.5802%]
                        Performance has regressed.
```

Release Notes:

- N/A
````

## Parents

- [2284131bfcdc0ee149f51b9edf11efa7fe1357f4](https://git.cafe/gitcafe/zed/commit/2284131bfcdc0ee149f51b9edf11efa7fe1357f4?format=markdown)

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