Skip to content

docs: note that value handlers copy their stored value - #141

Merged
biobo-bot[bot] merged 1 commit into
mainfrom
docs/value-handler-cost
Nov 27, 2026
Merged

biobo-bot[bot] merged 1 commit into
mainfrom
docs/value-handler-cost

Conversation

@sentomk

@sentomk sentomk commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Summary

Closes #132. Documents that a value handler (pattern >> value)
returns a copy of its stored value on every match, and points to the
forms that avoid an expensive copy: | to<T>, on<R>, or a lambda.
No code changes.

Changes

  • docs/api.md: a paragraph under pattern >> handler on the copy,
    with _ >> Ignored{} | to<Outcome>, on<Outcome>(...) and a
    lambda as alternatives, and a link to the tuning guide.
  • docs/guide/performance-tuning.md: new Value handlers section.
    It says when the copy is free (integers, enums, string literals,
    literal tables), that PTN_ON caching does not remove it, shows the
    alternatives on a variant and a string result, and quotes the
    measurements from Value handlers copy their stored value on every match #132.

Testing

  • Compiled and ran each snippet from the new text (with accept
    defined as Accepted accept(const Order &)) with Apple clang and
    GCC 13, -std=c++17.

Problem

A value handler returns a copy of its stored value each time its case
is selected. For a std::string or a std::variant holding one, that
copy made a fallback 2 to 2.7 times slower than building the value in
a lambda, and the docs gave no hint of it.

Implementation

docs/api.md explains the copy under the handler forms and shows the
existing alternatives: store a cheap value and convert it with
| to<T> or on<R>, or use a lambda. docs/guide/performance-tuning.md
gets a Value handlers section with the same advice, a note that
caching with PTN_ON does not remove the copy, and the measurements
from issue #132.

Tests

Compiled and ran every snippet in the new text with Apple clang and
GCC 13.

Closes #132

@biobo-bot biobo-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@biobo-bot
biobo-bot Bot merged commit 2fcb849 into main Nov 27, 2026
29 checks passed
@biobo-bot
biobo-bot Bot deleted the docs/value-handler-cost branch November 27, 2026 13:21
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.

Value handlers copy their stored value on every match

1 participant