Skip to content

perf: amortize repeated scalar concat-assignment growth #1298

Closed

Description

@fglock

Repeated Perl concat-assignment (for example, building a parser token one character at a time with .=) currently risks copying the complete Java String prefix on every append. This produces quadratic time and can turn ordinary multi-megabyte inputs into apparent hangs.

The immediate Selenium::Remote::Driver regression provides a concrete example: JSON::PP decodes a 3.4 MB mocked response with an escaped body using repeated scalar appends.

Investigate a runtime-level amortized representation for ordinary growing string scalars, with materialization at observable boundaries. Preserve Perl behavior for aliases, UTF-8 versus byte-string flags, tied and overloaded scalars, scalar magic/watchers, serialization, and both JVM and interpreter backends.

Acceptance criteria:

  • Repeated .= growth is linear or amortized-linear for plain strings.
  • Existing scalar semantics remain unchanged at read, assignment, and interop boundaries.
  • Include focused performance/regression coverage and benchmarks for parser-style large inputs.

Activity

  1. added
    enhancement
    area:runtime
    area:performance
    on Sep 8, 2026
  2. fglock commented on Nov 9, 2026

    @fglock
    OwnerAuthor

    State: active
    Agent/session: Codex / combined performance fixes 2026-11-09
    Scope: #1298 repeated scalar .=; reproduce/profile parser-style growth and preserve scalar semantics.
    Work: fix/anchored-regex-and-scalar-concat, source 54f02716b; PR #2002 open against master.
    Checkpoint: 2026-11-09. Async-profiler captured 1,488 samples through StringOperators.stringConcat and String.charAt during literal appends. The fast path rejected RuntimeScalarReadOnly string literals. StringOperators now permits that immutable RHS type while retaining the existing overload, tied-scalar, bytes and mutable-target guards. PR #1938 modifies RuntimeScalar but not this operator path; the fix leaves scalar ownership code untouched.
    Evidence: extended capture, converted to collapsed CPU samples. The 3.4M single-character workload changed from timing out at 240s on the parent to 0.878s on the candidate JVM and 1.722s on interpreter. The new literal-append unit checks pass system Perl and both backends. Full make and make check-links passed.
    Blocked by: none.
    Next: monitor PR #2002 CI and review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:performancearea:runtimeenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions