Groups | Search | Server Info | Login | Register


Groups > perl.perl5.changes > #34446

[Perl/perl5] b3f68b: Convert OP_CONST hash keys in key+val lists to HEKs

Newsgroups perl.perl5.changes
Path csiph.com!weretis.net!feeder8.news.weretis.net!fu-berlin.de!bofh.it!nntp.perl.org
Xref csiph.com perl.perl5.changes:34446
Return-Path <noreply@github.com>
Mailing-List contact perl5-changes-help@perl.org; run by ezmlm
Delivered-To mailing list perl5-changes@perl.org
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=perl.org; h=date :from:to:message-id:subject:mime-version:content-type :content-transfer-encoding:list-unsubscribe:reply-to; s=dr1; bh= sAwX39e0Z1fzZBBTg2pqZkukiwDCPHnUfcLB7zNRBsw=; b=LUTLpVmLGB6GFMLL owNPVzadkL/pV1ws3/92iPnImYOfde5UHD+IirCGC2vsLWIJVhDeCaCjhC9nMUow JQr/nNrPYce0eAoEGyeF4VLxiQDsTx8FOQZBLyh5UoAjJuM5LZ0B4dxtVHYwTNh/ m7U1+aO49k5JnzfV4JmS5EKaXIQmLFrtBQmkIJ937FfjUqP8Ms85IVv3EO0NyGC7 Xa8o/GCP5PiQDlTwYlq+HGlGtoXpAmkYLyNAuPEeVSNQszX8GJb6rodEd0YxUOvn tZfn5IGjjkyWrFUZ85yi6XvO149IxXcfObL4Ir8AtesA+eixQUEYRQgozVt324PY P4CLAw==
Received (qmail 26629 invoked from network); 10 Mar 2026 23:47:16 -0000
Received from xx1.develooper.com (147.75.38.233) by x6.develooper.com with SMTP; 10 Mar 2026 23:47:16 -0000
Received from inbound-egress-7.mailchannels.net (inbound-egress-7.mailchannels.net [23.83.220.5]) by xx1.develooper.com (Postfix) with ESMTP id 96F507C1BE for <perl5-changes@perl.org>; Tue, 10 Mar 2026 16:47:15 -0700 (PDT)
ARC-Seal i=1; a=rsa-sha256; d=mailchannels.net; s=arc-2022; cv=none; t=1773186434; b=xGB6N2KyjSCHYu48DV/DS7mvDoSv3NFO3C46yf0iMh9MH3oDlnGGGl7W2lUs9NHHwEAPx1 RGIkYrCShSucaQvEBpdq6zDOhPMBBhhrkGW4KFSBgECT/F87ZtKqtONnPNljftAx+WBbCd /pePsBtTgUbjBmtDg3L3l7m38LcOnvJLXz3mFfQZ05EuZDW1tseLEU94pYCosUwj1YFBxF uK8/s5yHPPiwkFdzh8clgwHsjKOKyVc+a+nQvq23PzbLC4+OmItV52ycjMPPbjEj++H4lY 6AoIPTYz8miRu9fZs5ExvnRDtR5O58aa6h6bUc3B6ZT6zBfZujL2V1+n12hPuw==
ARC-Message-Signature i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1773186434; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-unsubscribe: dkim-signature; bh=sAwX39e0Z1fzZBBTg2pqZkukiwDCPHnUfcLB7zNRBsw=; b=hG/qyAeH6aGe4uGD1WIzMa4PTksYbdkm5hFCrQJVOhBJQ8c9ccrrRTEykaj6PIl9DBXqvr fN0PZZGcEMtHgkCqNCvgytTZhtudXOjm5AIWvmJYkdFf3HquTyRDMDBGNouCtztEZgbZ0W C924KEY8StoOuY70b4bJ0lqR9RbLkQjF8xHcTwFbTI3mGjdeyqezPk4GjuIqGWDQU1EKnB 4lrQmeMJ00Dl8HNdu8/Ohjdkq95+XfjIChi54bHEL9e1LSSiOgwZvDFrbkL0onoufwKjgm Ebr9p9glIf9tsPWuNR5tRqCz45SaLWseu/PCkh1T9fYHRZJ/h4EK1b5orurJrw==
ARC-Authentication-Results i=1; inbound-rspamd-57bbd4d544-6c4zf; none
X-Message-ID ZYvMQwhGa6J4HYheKvC3GQpF
Received from out-22.smtp.github.com (out-22.smtp.github.com [192.30.252.205]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.107.84.214 (trex/7.1.4); Tue, 10 Mar 2026 23:47:14 +0000
Authentication-Results inbound.mailchannels.net; spf=pass smtp.mailfrom=noreply@github.com; dkim=pass header.d=github.com; dmarc=pass (policy=reject; pct=100; status=pass); arc=none
Received-SPF pass (dmarc-service-78968d7585-9zbg6: domain of github.com designates 192.30.252.205 as permitted sender) client-ip=192.30.252.205; envelope-from=noreply@github.com; helo=out-22.smtp.github.com;
Received from github.com (hubbernetes-node-6f0d472.ac4-iad.github.net [10.55.96.33]) by smtp.github.com (Postfix) with ESMTPA id 61BA42094A for <perl5-changes@perl.org>; Tue, 10 Mar 2026 16:47:13 -0700 (PDT)
Date Tue, 10 Mar 2026 16:47:13 -0700
To perl5-changes@perl.org
Message-ID <Perl/perl5/push/refs/heads/blead/e75458-23045b@github.com> (permalink)
Subject [Perl/perl5] b3f68b: Convert OP_CONST hash keys in key+val lists to HEKs
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 7bit
X-GitHub-Recipient-Address perl5-changes@perl.org
X-Auto-Response-Suppress All
Original-From Richard Leach <noreply@github.com>
Reply-To Richard Leach <noreply@github.com>,
Approved news@nntp.perl.org
From perl5-changes@perl.org (Richard Leach via perl5-changes)

Show key headers only | View raw


  Branch: refs/heads/blead
  Home:   https://github.com/Perl/perl5
  Commit: b3f68b479c9876437620503fb7d54e14bceadcee
      https://github.com/Perl/perl5/commit/b3f68b479c9876437620503fb7d54e14bceadcee
  Author: Richard Leach <richardleach@users.noreply.github.com>
  Date:   2026-03-10 (Tue, 10 Mar 2026)

  Changed paths:
    M embed.fnc
    M embed.h
    M lib/B/Deparse.t
    M op.c
    M opcode.h
    M proto.h
    M regen/op_private
    M regen/opcodes

  Log Message:
  -----------
  Convert OP_CONST hash keys in key+val lists to HEKs

Hash operations in perl are faster when operating upon a `keysv` that
uses a `HEK` to represent the key. Hash entry comparisons can then be
more lightweight as `HEK` pointer comparisons can be used instead of:
* Re-deriving the hash each time the key is used
* Exhaustive comparison of the hash key values and flags

Some `OP_CONST` SVs that are destined for use as hash keys are already
converted (_hekified_) during compilation, such as the arguments to
`OP_HELEM`, `OP_MULTIDEREF`, or `OP_HSLICE`/`OP_KVSLICE`.
`Perl_check_hash_fields_and_hekify`, which operates on sequential SV
pointers, does the work in those cases.

This commit _hekifies_ `OP_CONST` SV keys - providing they are `SvPOK`
and therefore not subject to locale-specific coercion at run time -
in key+value `SV*` lists, such as in the arguments to `OP_ANONHASH`:

    my $href = { one => 1, two => 2, three => 3, four => 4 };

and `OP_AASSIGN` (note: may not cover all possible LVALUE constructions):

    my %h = ( one => 1, two => 2, three => 3, four => 4 );

`OP_CONST` SVs in the value positions are not _hekified_, as the process
involves attempted downgrade of UTF8 strings, which could result in
user-visible behaviour changes (such as in the comparison of string contents).

For this reason, this optimization returns early when either key or
value OPs have the potential to return more than one value - it becomes
impossible to be sure at compile time whether subsequent OPs represent
keys or values.

As a contrived example: in the following statement, the compiler
cannot be _absolutely_ sure that 'three' will be used as as a key
and `3` is its matching value.

    my $h = (one => 1, @two, three => 3, @four);

Changes in this commit are:
* Addition of the `S_check_alt_hash_fields_hekify` function
* Addition of dedicated `ck` functions for `anonhash` and `aassign`

Comparing `for (0..100_000_000) { my %h = (one => 1, two => 2, three => 3, four => 4); }`:

*Blead*
```
         20,409.44 msec task-clock                       #    1.000 CPUs utilized
               117      context-switches                 #    5.733 /sec
                 0      cpu-migrations                   #    0.000 /sec
               190      page-faults                      #    9.309 /sec
    93,850,595,514      cycles                           #    4.598 GHz
   354,784,740,965      instructions                     #    3.78  insn per cycle
    73,658,057,571      branches                         #    3.609 G/sec
        51,196,358      branch-misses                    #    0.07% of all branches
```
*Patched*
```
         15,295.49 msec task-clock                       #    1.000 CPUs utilized
                79      context-switches                 #    5.165 /sec
                 1      cpu-migrations                   #    0.065 /sec
               195      page-faults                      #   12.749 /sec
    70,493,543,069      cycles                           #    4.609 GHz
   272,426,451,548      instructions                     #    3.86  insn per cycle
    55,406,135,074      branches                         #    3.622 G/sec
       100,887,629      branch-misses                    #    0.18% of all branches
```

Comparing `for (0..100_000_000) { my $h = {one => 1, two => 2, three => 3, four => 4}; }`

*blead*
```
         21,088.71 msec task-clock                       #    1.000 CPUs utilized
               100      context-switches                 #    4.742 /sec
                 2      cpu-migrations                   #    0.095 /sec
               195      page-faults                      #    9.247 /sec
    97,377,416,887      cycles                           #    4.618 GHz
   376,434,236,222      instructions                     #    3.87  insn per cycle
    81,607,926,506      branches                         #    3.870 G/sec
         1,159,167      branch-misses                    #    0.00% of all branches
```
*patched*
```
         16,150.16 msec task-clock                       #    1.000 CPUs utilized
                79      context-switches                 #    4.892 /sec
                 0      cpu-migrations                   #    0.000 /sec
               193      page-faults                      #   11.950 /sec
    74,465,581,333      cycles                           #    4.611 GHz
   298,176,803,158      instructions                     #    4.00  insn per cycle
    63,656,208,147      branches                         #    3.942 G/sec
        50,869,763      branch-misses                    #    0.08% of all branches
```

Note: This will stack with [GH #24149], which reduced branch-misses.


  Commit: 23045b021a96bec42a6510c41d695d90411d23af
      https://github.com/Perl/perl5/commit/23045b021a96bec42a6510c41d695d90411d23af
  Author: Richard Leach <richardleach@users.noreply.github.com>
  Date:   2026-03-10 (Tue, 10 Mar 2026)

  Changed paths:
    M pod/perldelta.pod

  Log Message:
  -----------
  Perldelta entry for GH#24228


Compare: https://github.com/Perl/perl5/compare/e754582d735a...23045b021a96

To unsubscribe from these emails, change your notification settings at https://github.com/Perl/perl5/settings/notifications

Back to perl.perl5.changes | Previous | Find similar


Thread

[Perl/perl5] b3f68b: Convert OP_CONST hash keys in key+val lists to HEKs perl5-changes@perl.org (Richard Leach via perl5-changes) - 2026-03-10 16:47 -0700

csiph-web