develooper Front page | perl.perl5.changes | Postings from October 2021

[Perl/perl5] 53a41f: Inline the xhv_aux struct in the main hash body

From:
Nicholas Clark via perl5-changes
Date:
October 11, 2021 12:06
Subject:
[Perl/perl5] 53a41f: Inline the xhv_aux struct in the main hash body
Message ID:
Perl/perl5/push/refs/heads/blead/cf927c-e43d28@github.com
  Branch: refs/heads/blead
  Home:   https://github.com/Perl/perl5
  Commit: 53a41f9c2c0671d8e97b2d47afa3130fe376f322
      https://github.com/Perl/perl5/commit/53a41f9c2c0671d8e97b2d47afa3130fe376f322
  Author: Nicholas Clark <nick@ccl4.org>
  Date:   2021-10-11 (Mon, 11 Oct 2021)

  Changed paths:
    M hv.c
    M hv.h
    M sv.c

  Log Message:
  -----------
  Inline the xhv_aux struct in the main hash body

For now, memory for this structure is always allocated, even though it
isn't always flagged as being present.


  Commit: 0095ebd8b96d81e41d1fa374c2d31b189d2dee9e
      https://github.com/Perl/perl5/commit/0095ebd8b96d81e41d1fa374c2d31b189d2dee9e
  Author: Nicholas Clark <nick@ccl4.org>
  Date:   2021-10-11 (Mon, 11 Oct 2021)

  Changed paths:
    M hv.c

  Log Message:
  -----------
  No need to set dest->xhv_rand in S_hsplit() called from hv_common()

Perl_hv_common() only calls S_hsplit() after inserting a new hash key, if
the hash meets the "split" criteria. Inserting the new hash key has already
set HvAUX(hv)->xhv_rand to PL_hash_rand_bits (if the hash has an aux
struct), so no need to repeat the same assignment in S_hsplit() for this
case.

However, this code path in S_hsplit() can also be reached from
Perl_hv_ksplit() for the case of assigning to `keys %hash` for a hash which
has an aux struct. The call to `keys` resets the hash iterator (in LVALUE
context as well as RVALUE context), but when the assignment changed the
bucket size this also had the size effect of causing a new iteration order.

It's not clear whether this really matters for security of the internal hash
state, but as this behaviour is both observable and can easily be retained,
it seems worthwhile adding the small amount of extra code needed to keep it.

Hence this commit is (or is intended to be) a pure refactoring, without any
observable behaviour change.


  Commit: 15b39af41614cf0fa1a6931a63dba1bbbcd2c2b5
      https://github.com/Perl/perl5/commit/15b39af41614cf0fa1a6931a63dba1bbbcd2c2b5
  Author: Nicholas Clark <nick@ccl4.org>
  Date:   2021-10-11 (Mon, 11 Oct 2021)

  Changed paths:
    M hv.c
    M hv.h

  Log Message:
  -----------
  Delete the do_aux code from S_hsplit()

This existed to handle automatically allocating an "aux" structure for
larger hashes, to save a (large) reallocation if they needed to be iterated.

Now that we no longer store the aux structure in the main hash array, we
don't need to take this precaution.


  Commit: 9710057bff258cbe68d25e718b0eeecf5c92cccc
      https://github.com/Perl/perl5/commit/9710057bff258cbe68d25e718b0eeecf5c92cccc
  Author: Nicholas Clark <nick@ccl4.org>
  Date:   2021-10-11 (Mon, 11 Oct 2021)

  Changed paths:
    M embed.fnc
    M embed.h
    M hv.c
    M proto.h

  Log Message:
  -----------
  Inline S_hv_auxinit_internal() into S_hv_auxinit()

The previous commit eliminated the only other use of S_hv_auxinit_internal().


  Commit: caf0b9e5682bde101a4ee56b69daee5f3362ad0e
      https://github.com/Perl/perl5/commit/caf0b9e5682bde101a4ee56b69daee5f3362ad0e
  Author: Nicholas Clark <nick@ccl4.org>
  Date:   2021-10-11 (Mon, 11 Oct 2021)

  Changed paths:
    M ext/XS-APItest/APItest.pm
    M ext/XS-APItest/APItest.xs
    M hv.c
    M sv.c
    M sv.h

  Log Message:
  -----------
  Rename HE_SVSLOT to HE_ARENA_ROOT_IX

The longer name more accurately reflects what the constant refers to.

Correct the comments describing how some arena roots are re-used.


  Commit: 9faee2eae78e645be21d3d1de656460e8ea20f60
      https://github.com/Perl/perl5/commit/9faee2eae78e645be21d3d1de656460e8ea20f60
  Author: Nicholas Clark <nick@ccl4.org>
  Date:   2021-10-11 (Mon, 11 Oct 2021)

  Changed paths:
    M sv.c

  Log Message:
  -----------
  Move variables in Perl_sv_clear() to a tighter scope.

These three variables don't hold their values between iterations of the
while loop, so can be declared within it, to make this obvious.


  Commit: 36149847e29e423be58d70fad50d9908be1d0373
      https://github.com/Perl/perl5/commit/36149847e29e423be58d70fad50d9908be1d0373
  Author: Nicholas Clark <nick@ccl4.org>
  Date:   2021-10-11 (Mon, 11 Oct 2021)

  Changed paths:
    M sv.c

  Log Message:
  -----------
  Change S_new_body to static inline, and use it instead of a macro

Rename the macro new_body_inline() to new_body_from_arena().

The macro existed to provide an inline implementation for hot code paths,
with a small function for the others. Now that we have proper inline
functions, change the function to be inlined, and use it instead of the
macro. There is no change to the code generated for the hot paths. This
makes the source simpler.

Yes, this will also inline the function in a couple of other places, but
these days optimising compilers often do that anyway for small functions.
Even if they aren't for this function (as was), the size of the function
itself is comparable with the calling overheads, so it's not a massive
penalty.

Two if blocks now need to be placed inside #ifndef PURIFY/#endif guards
because they now use the function S_new_body(), which is not defined with
PURIFY. The code is actually unreachable - defining PURIFY causes all
values for new_type_details->arena to be forced to 0 - hence the if was
never true under PURIFY. Hence it could have been guarded the same way
previously, but for (maybe false) improved readability was not. Previously
there wasn't a compilation failure because the unreachable code was using
a macro, not a static function, and the macro was always defined, even when
not used.

Really the macro's definition should have been inside #ifndef PURIFY, so
fix this oversight - it is now only defined if it is needed.

Retain the macro (with a new name), and split the parameters to the macro.
This will make the next commit simpler.


  Commit: 94ee6ed79dbca73d0345b745534477e4017fb990
      https://github.com/Perl/perl5/commit/94ee6ed79dbca73d0345b745534477e4017fb990
  Author: Nicholas Clark <nick@ccl4.org>
  Date:   2021-10-11 (Mon, 11 Oct 2021)

  Changed paths:
    M embed.fnc
    M hv.c
    M hv.h
    M proto.h
    M sv.c
    M sv.h

  Log Message:
  -----------
  Split the XPVHV body into two variants "normal" and "with aux"

Default to the smaller body, and switch to the larger body if we need to
allocate a C<struct xpvhv_aux> (eg need an iterator).

This restores the previous small size optimisation for hashes used as
objects.


  Commit: 65fd1a752307d06bd94b4da2dd6aec5aaa9e3dd9
      https://github.com/Perl/perl5/commit/65fd1a752307d06bd94b4da2dd6aec5aaa9e3dd9
  Author: Nicholas Clark <nick@ccl4.org>
  Date:   2021-10-11 (Mon, 11 Oct 2021)

  Changed paths:
    M hv.c

  Log Message:
  -----------
  Re-reading HvAUX(hv) is no longer necessary

Now that HvAUX(hv) is allocated as part of the HV's body, it no longer
moves in memory if the hash is resized. Hence there is no need to update
local copies of the pointer after any potential move, so remove the code
that did this.


  Commit: e43d289c7c581c1a5094e7bade06b9cdbaeb430f
      https://github.com/Perl/perl5/commit/e43d289c7c581c1a5094e7bade06b9cdbaeb430f
  Author: Nicholas Clark <nick@ccl4.org>
  Date:   2021-10-11 (Mon, 11 Oct 2021)

  Changed paths:
    M pod/perldelta.pod

  Log Message:
  -----------
  perldelta entry describing the HvAUX struct move to the HV body

None of this affects documented public XS interfaces. The only code changes
are in hv.c and sv.c. As the rest of the core itself uses these macros but
needed no changes, likely no code on CPAN will be affected either.


Compare: https://github.com/Perl/perl5/compare/cf927cca44dd...e43d289c7c58



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About