develooper Front page | perl.perl5.changes | Postings from November 2022

[Perl/perl5] dbf361: Extract minimum PV buffer/AV element size tocommo...

From:
Richard Leach via perl5-changes
Date:
November 21, 2022 11:40
Subject:
[Perl/perl5] dbf361: Extract minimum PV buffer/AV element size tocommo...
Message ID:
Perl/perl5/push/refs/heads/blead/b17e77-06dbff@github.com
  Branch: refs/heads/blead
  Home:   https://github.com/Perl/perl5
  Commit: dbf3614df92e720a9536b1cceb915a18ff2b8c08
      https://github.com/Perl/perl5/commit/dbf3614df92e720a9536b1cceb915a18ff2b8c08
  Author: Richard Leach <richardleach@users.noreply.github.com>
  Date:   2022-11-21 (Mon, 21 Nov 2022)

  Changed paths:
    M av.c
    M perl.h
    M pp_hot.c
    M sv.c

  Log Message:
  -----------
  Extract minimum PV buffer/AV element size to common definitions

In a nutshell, for a long time the minimum PV length (hardcoded
in Perl_sv_grow) has been 10 bytes and the minimum AV array size
(hardcoded in av_extend_guts) has been 4 elements.

These numbers have been used elsewhere for consistency (e.g.
Perl_sv_grow_fresh) in the past couple of development cycles.
Having a standard definition, rather than hardcoding in multiple
places, is more maintainable. This commit therefore introduces
into perl.h:

    PERL_ARRAY_NEW_MIN_KEY
    PERL_STRLEN_NEW_MIN

(Note: Subsequent commit(s) will actually change the values.)


  Commit: 06dbfffcf611d03ad6078d4049e84de53458f9c9
      https://github.com/Perl/perl5/commit/06dbfffcf611d03ad6078d4049e84de53458f9c9
  Author: Richard Leach <richardleach@users.noreply.github.com>
  Date:   2022-11-21 (Mon, 21 Nov 2022)

  Changed paths:
    M perl.h

  Log Message:
  -----------
  PERL_STRLEN_NEW_MIN - increase to multiple of pointer sizes

Major malloc implementations, including the popular dlmalloc
derivatives all return chunks of memory that are a multiple of
the platform's pointer size. Perl's traditional default string
allocation of 10 bytes will almost certainly result in a larger
allocation than requested. Consequently, the interpreter may try
to Renew() an allocation to increase the PV buffer size when it
does not actually need to do so.

This commit increases the default string size to the nearest
pointer multiple. (12 bytes for 32-bit pointers, 16 bytes for
64-bit pointers). This is almost certainly unnecessarily small
for 64-bit platforms, since most common malloc implementations
seem to return 3*pointer size (i.e. 24 bytes) as the smallest
allocation. However, 16 bytes was chosen to prevent an increase
in memory usage in memory-constrained platforms which might have
a smaller minimum memory allocation.


Compare: https://github.com/Perl/perl5/compare/b17e77fbd875...06dbfffcf611



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