Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select optimization: Avoid backtracking on mutually exclusive branches #158

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Andersama
Copy link
Contributor

@Andersama Andersama commented Dec 27, 2020

When we match against characters that belong to no other select branch we can avoid backtracking by a significant amount.
Note: HeadOptions could be a fairly large sequence*. I updated to use calculate_first() to evaluate the initial condition and backtrack by at worst one character*

See comparison: https://compiler-explorer.com/z/8ea8Pr
*Updated: https://compiler-explorer.com/z/vPEq1T

@Andersama Andersama changed the title select optimization: avoid backtracking on mutually exclusive branches Select optimization: Avoid backtracking on mutually exclusive branches Dec 27, 2020
@Andersama Andersama force-pushed the patch-2 branch 4 times, most recently from 3bbd78a to e5fb7cd Compare January 2, 2021 15:08
When we match against characters that belong to no other select branch we can avoid backtracking by a significant amount.
Note: HeadOptions could be a fairly large sequence, here we use calculate_first() to evaluate the initial condition for a mutually exclusive branch*
@hanickadot
Copy link
Owner

I actually did this once, and found out the resulting assembly is worse, the first character lookahead is useful mostly only for cycles. And only for optimizations.

@Andersama
Copy link
Contributor Author

Andersama commented Jul 18, 2021

Was it more like this pr or the other one? I just rewrote this because with that bug patched something kinda clicked, and this one only handles when the branch is mutually exclusive from everything else. The newer approach could be useful not necessarily for a one character lookahead it could be just to reorder the select expression around for the branch predictor.

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