-
Notifications
You must be signed in to change notification settings - Fork 594
Faster feature checks #17229
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
Faster feature checks #17229
Conversation
this excellent! |
* Check whether the named feature is enabled. | ||
*/ | ||
bool | ||
Perl_feature_is_enabled(pTHX_ const char *const name, STRLEN namelen) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note that we will also have to remove or adjust feature_is_enabled
from Devel::PPPort
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably remove, feature_is_enabled was only used by FEATURE_IS_ENABLED(), which is only intended for use by core or included extensions (PERL_EXT).
@@ -76,6 +76,17 @@ BEGIN | |||
########################################################################### | |||
# More data generated from the above | |||
|
|||
if (keys %feature > 32) { | |||
die "cop_features only has room for 32 features"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would be the thing to do if we run out of bits? Can we easily turn the field into a U64, or would we make a second one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If U64 can be used, it may make sense to reuse cop_hints
(it's a U32, but 28 of its bits are currently in use)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplest for working with feature.pm/${^FEATURE_BITS} would probably be a U8 array, but that's difficult to write a SAVEFEATUREBITS() for.
We could make it a pointer as for warnings, but since the feature bits are fixed size and will be present in any cop, the pointer is just overhead.
But for now we have over twice the feature bits as features, so I don't feel much urgency to decide right now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If U64 can be used, it may make sense to reuse
cop_hints
(it's a U32, but 28 of its bits are currently in use)
If we worked through $^H we'd need to require -Duse64bitint to safely update it from feature.pm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
Perform only a bit check instead of a much more expensive hash lookup to test features. For now I've just added a U32 to the cop structure to store the bits, if we need more we could either add more bits directly, or make it a pointer. We don't have the immediate need for a pointer that warning do since we don't dynamically add new features during compilation/runtime. The changes to %^H are retained so that caller() can be used from perl code to check the features enabled at a given caller's scope.
712b4ac
to
298a079
Compare
This currently leaves no way for a user to manually construct a |
@haarg Perhaps this could be solved by
|
That would make sense to me. |
Why do they need it? If they want to enable features they can use feature->(un)import() in the current compilation. It also risks the feature bits and %^H feature entries getting out of sync. I'd rather remove ${^FEATURE_BITS} rather than even vaguely suggest it's something users should be touching. That said, there is a way to get the bits for a given feature set: call feature->import() at runtime with the features you want, and extract the bits. |
It remains to be seen whether such a feature would be needed, but it can be added in a small addition to |
I've merged this, I may end up removing ${^FEATURE_BITS} (but keeping the optimization) |
|
I had a look at this, I don't think it's worth reinstating FEATURE_IS_ENABLED() / Perl_feature_is_enabled() to save this bit. Opinions welcome. |
It's not saving a bit that I'm worried about, but more things like "what happens if they're out of sync?". Also, |
The out of sync could happen between Losing sync between I've considered eliminating the visibility of |
There are modules that copy the values of I think having yet another lexical hints variable is something that should be avoided. |
No description provided.