Skip to content

Can POK CONST SVs share buffers for identical strings? #23409

@richardleach

Description

@richardleach

Description
(Mentioned somewhere recently, I think by @bulk88, but I couldn't locate it just now.)

POK CONST OPs that happen to have the same string content will each have their own IsCOW buffer.
For example, when the following is compiled, there will be three distinct allocations containing the word "perl", each attached to a separate CONST OP's SV:

sub consts {
    my $x = "perl";
    if ($_[0] eq "perl") {
        say "perl"
    }
}

Having just one allocation for "perl" rather than three would seem nice. Is there a fundamental reason for the current implementation, or does it just predate the shared string table and COW mechanisms?

If it's just a case of tuits, what would the next steps be, and should the approach be shared strings in PL_strtab or something else that results in a shared buffers for such CONST OPs?

Note: toke.c produces OP_CONST OPs via multiple different, non-identical paths. Any sharing implementation might best be implemented as:

  1. A proof-of-concept in Perl_ck_svconst that takes the OP's SVs as currently built and consolidates them.

Possibly in a later dev cycle:

  1. Amend the multiple OP_CONST construction sites in toke.c such that the sharing happens earlier and more efficiently.

Perl configuration
Blead and previous.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions