Skip to content

perf: reduce reference-counting overhead and DBIx::Class warnings - #871

Merged
fglock merged 3 commits into
masterfrom
perf/refcount-runtime-overhead
Jul 28, 2026
Merged

perf: reduce reference-counting overhead and DBIx::Class warnings#871
fglock merged 3 commits into
masterfrom
perf/refcount-runtime-overhead

Conversation

@fglock

@fglock fglock commented Jul 27, 2026

Copy link
Copy Markdown
Owner

Summary

  • register tracked scalar owners once after DESTROY-rescue handling instead of twice
  • remove redundant synchronized wrappers from the explicitly single-threaded scalar registry
  • remove empty reverse weak-reference buckets during unweaken
  • stop caught optional base::import failures from printing duplicate stderr diagnostics
  • align bundled DynaLoader and bytes file versions with their Java runtime versions
  • patch Exception::Class 1.45 generated subclasses to match the source file registered in %INC
  • preserve weak references to readonly constants while their defining subroutine remains installed
  • add focused performance and version-consistency regression coverage

Performance

Three fresh JVM runs of dev/bench/benchmark_refcount_store.pl:

Revision Median CPU time
master (168466619) 2.71 s
this branch 2.41 s

This is an 11.1% reduction in CPU time for tracked reference stores after weaken() activates lifecycle bookkeeping.

The ordinary method benchmark remained approximately 2.35 CPU seconds on both revisions.

DBIx::Class warnings

t/00describe_environment.t no longer reports:

  • empty Getopt::Long::Descriptive base packages from caught optional-dependency probes
  • Params::ValidationCompiler generated exception version mismatches
  • DynaLoader or bytes runtime/file version mismatches

Exception::Class 1.45 still contains the upstream 1.1/1.45 mismatch; the CPAN distroprefs patch keeps the generated class version consistent with Exception/Class.pm while preserving its %INC registration.

Moo weak accessors

Readonly scalars created by \ "literal" are strongly owned by their defining subroutine's pad, but that edge is invisible to selective refcounting. Moo passes these references through constructor temporaries before weakening an attribute, which previously let mortal processing clear the value immediately.

The runtime now recognizes readonly scalars in installed subroutine pads as strongly owned. Replacing the subroutine still clears the weak reference through the existing optree-reaping hook.

Validation

  • standard Perl: prove src/test/resources/unit/core_module_file_versions.t
  • PerlOnJava: ./jperl src/test/resources/unit/core_module_file_versions.t
  • Exception::Class 1.45: 7 files, 86 tests, all successful
  • DBIx::Class t/00describe_environment.t: passed with none of the targeted warnings
  • ./jcpan -t Moo: 71 files, 841 tests, all successful
  • make: successful
  • ./jcpan --jobs 8 -t DBIx::Class
    • 314 files
    • 13,121 tests
    • 695 seconds wall time after the Moo fix
    • all tests successful

Safety notes

Two broader reference-counting optimizations were evaluated and rejected after unit-test regressions:

  • conditionally skipping temporary reachability roots
  • resetting the global weak-reference mode after the last weak reference cleared

The retained performance changes preserve the existing lifecycle state machine. The warning changes retain catchable base exceptions and validate file/runtime version consistency with a portable test that also passes on standard Perl.

Generated with Codex

fglock and others added 2 commits July 27, 2026 10:44
Register owned scalar references once after rescue handling, remove
unnecessary synchronization from the single-threaded weak scalar registry,
and release empty reverse weak-reference buckets on unweaken.

Add a focused tracked-store benchmark and document the measured 11.1%
median CPU improvement and full DBIx::Class validation.

Generated with [Codex](https://openai.com/codex)

Co-Authored-By: Codex <codex@openai.com>
Keep caught base::import failures from leaking duplicate stderr output,
align bundled core module versions with their runtime values, and patch
Exception::Class generated subclasses to match their registered source file.

Generated with [Codex](https://openai.com/codex)

Co-Authored-By: Codex <codex@openai.com>
@fglock fglock changed the title perf: reduce tracked reference store overhead perf: reduce reference-counting overhead and DBIx::Class warnings Jul 27, 2026
Treat readonly scalars referenced by an installed subroutine's pad as
strongly owned until glob replacement performs optree reaping. This keeps
Moo weak_ref constructor values alive without changing ordinary tracked
reference-store behavior.

Generated with [Codex](https://openai.com/codex)

Co-Authored-By: Codex <codex@openai.com>
@fglock
fglock merged commit ae98774 into master Jul 28, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant