Skip to content

perf: remove index panic code generation from ExtractIf next - #587

Merged
alejandro-vaz merged 1 commit into
servo:v2from
fereidani:v2_extract_if_optimize
Sep 6, 2026
Merged

perf: remove index panic code generation from ExtractIf next#587
alejandro-vaz merged 1 commit into
servo:v2from
fereidani:v2_extract_if_optimize

Conversation

@fereidani

Copy link
Copy Markdown
Contributor

While reviewing panic paths of smallvec I noticed we have a index check panic in ExtractIf next function.

I checked it with the rust alloc itself and updated the algorithm to remove that mistake.
I believe this mistake was a port of the old rust alloc which got optimized later.

@fereidani

Copy link
Copy Markdown
Contributor Author

note: The PR code matches the current rust alloc implementation

@fereidani

Copy link
Copy Markdown
Contributor Author

You can check the panic paths further using panicgraph -l 8000 on the project. Removing panic paths in bottlenecks results in branchless code and therefore better performance.

@alejandro-vaz

alejandro-vaz commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator

yeah it's those tiny indexes and stuff like that that introduce unnecessary bound checks we already know code fulfills but LLVM can't

you could have gotten your way as well by doing unchecked accesses wouldn't you??

@alejandro-vaz
alejandro-vaz added this pull request to the merge queue Sep 6, 2026
Merged via the queue into servo:v2 with commit f30b0c1 Sep 6, 2026
6 checks passed
@fereidani

Copy link
Copy Markdown
Contributor Author

yeah it's those tiny indexes and stuff like that that introduce unnecessary bound checks we already know code fulfills but LLVM can't

Exactly, and that we are using unsafe anyway, so there is no need to use safe API and defeat the gain of unsafe.

you could have gotten your way as well by doing unchecked accesses wouldn't you??

Can you please give me an example? I'm not sure about what you mean.

@alejandro-vaz

alejandro-vaz commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator
unsafe { v.get_unchecked_mut(i) }

it's basically the same except that it doesn't do bound checks

@fereidani

Copy link
Copy Markdown
Contributor Author

Yeah but I think that would be ugly, and I would have to watch for double drops, I'll prefer pointer API for these kind of stuff.

@alejandro-vaz

Copy link
Copy Markdown
Collaborator

more of the same

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants