-
Notifications
You must be signed in to change notification settings - Fork 530
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
Don't zero non-real arrays #18690
Don't zero non-real arrays #18690
Conversation
A minor difference in behaviour introduced by the rewrite of av_extend_guts in 440c185 and 399fef9 is that when the SV* array is first acquired, we now zero its contents regardless of whether that is needed - and add an extra label and 'goto' to do so. This commit restores the original behavious: for non-refcounted arrays such as @_ and pad arrays this is not needed, and for pads in particular we may hit this path many times during the course of a program.
The original change was intentional with the thought being that not having to go through the I didn't consider many other kind of non-real arrays at the time, because I don't have a good feel for how common they are and what their creation/growth patterns look like. So me having missed something important of that nature is certainly possible. However, I did look at pad.c and noted that there's:
So I'm thinking that if pads don't need to be zeroed, the current behaviour in pad.c would have to be changed. |
PS I forgot in the reply above: in pad.c, there are also a number of direct (Other places in core also directly allocate their array and fix up the xpv pointers too. (av_make() does, there's something else that doesn't want the default sizing in another file IIRC. Something that might be nice would be a macro for doing Newx/z & pointer fixup, rather than all these places doing it themselves.) |
Are |
Was that a typo? When Anyway, I tried instrumenting with:
.. and for lack of a better example of realistic code, ran mktables up to the point of perl_destruct:
So colour me convinced - I'll withdraw this PR. Even though the test on i386 is just 4 instructions (including just a 1-byte memory read), it seems clear that performing that test 23558 times to avoid zeroing 436 * sizeof(SV*) bytes is a net loss. If someone has a more realistic workload on which to try the same instrumentation, I'd be interested to see it, but I think I'd expect it to tell essentially the same story. For future reference: it's really useful if behaviour changes like this are called out by a separate commit, even if that results in a commit that seems trivially small. |
A minor difference in behaviour introduced by the rewrite of av_extend_guts
in 440c185 and 399fef9 is that when the SV* array is first acquired, we
now zero its contents regardless of whether that is needed - and add an
extra label and 'goto' to do so.
This commit restores the original behaviour: for non-refcounted arrays such
as @_ and pad arrays this is not needed, and for pads in particular we may
hit this path many times during the course of a program.
@richardleach I mentioned this difference in #18667, but the focus there was on the ary_offset bug. If you think this requires further discussion I can also open a separate ticket for it.