Commit faca460
authored
Auto merge of #206 - hiddenhare:inline-constructors, r=mbrubeck
Add #[inline] attribute to all fns which return SmallVec
When rustc fails to inline a `SmallVec` constructor, it can carry a significant performance cost: for example, if `SmallVec::<[i64; 128]>::from_iter(...)` fails to inline, it will perform an unnecessary 1kb memcpy.
I've recently been bitten by this when using `SmallVec` in a context where rustc seemed to be reluctant to perform inlining (a large fn with nested closures). Switching from `SmallVec::from_iter` to `SmallVec::new` and `push`, with a buffer size of 256 bytes, saved over 20ns per call. For larger buffers, `from_iter` carried a proportionally higher cost, even when the actual capacity in use didn't change.1 file changed
+4
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1055 | 1055 | | |
1056 | 1056 | | |
1057 | 1057 | | |
| 1058 | + | |
1058 | 1059 | | |
1059 | 1060 | | |
1060 | 1061 | | |
| |||
1372 | 1373 | | |
1373 | 1374 | | |
1374 | 1375 | | |
| 1376 | + | |
1375 | 1377 | | |
1376 | 1378 | | |
1377 | 1379 | | |
| |||
1452 | 1454 | | |
1453 | 1455 | | |
1454 | 1456 | | |
| 1457 | + | |
1455 | 1458 | | |
1456 | 1459 | | |
1457 | 1460 | | |
| |||
1700 | 1703 | | |
1701 | 1704 | | |
1702 | 1705 | | |
| 1706 | + | |
1703 | 1707 | | |
1704 | 1708 | | |
1705 | 1709 | | |
| |||
0 commit comments