Skip to content

MONGOID-6016 Short-circuit database_field_name for keys without "." - #6200

Merged
jamis merged 2 commits into
mongodb:masterfrom
phedinkus:database-field-name-short-circuit
Oct 21, 2026
Merged

jamis merged 2 commits into
mongodb:masterfrom
phedinkus:database-field-name-short-circuit

Conversation

@phedinkus

Copy link
Copy Markdown
Contributor

database_field_name splits every key on "." and dups the alias on every call, even for plain field names. This allocates on one of the hottest read paths: in a load-and-read allocation profile it was the single largest source of new objects.

Short-circuit the common case -- a key with no "." resolves to its alias (or itself) without splitting. This mirrors the optimization already applied to the matcher in PR #5868. Behavior is unchanged; the returned alias is still duped so callers cannot mutate the stored value.

Measured ~50% fewer allocations per call for plain keys (4 -> 2) and ~40% for aliased keys (5 -> 3).

Fix for https://jira.mongodb.org/browse/MONGOID-6016

database_field_name splits every key on "." and dups the alias on every call,
even for plain field names. This allocates on one of the hottest read paths:
in a load-and-read allocation profile it was the single largest source of new
objects.

Short-circuit the common case -- a key with no "." resolves to its alias (or
itself) without splitting. This mirrors the optimization already applied to
the matcher in mongodb#5868. Behavior is unchanged; the returned alias is still
duped so callers cannot mutate the stored value.

Measured ~50% fewer allocations per call for plain keys (4 -> 2) and ~40% for
aliased keys (5 -> 3).
@phedinkus
phedinkus requested a review from a team as a code owner October 20, 2026 11:20
@phedinkus
phedinkus requested a review from jamis October 20, 2026 11:20

@jamis jamis 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.

This looks great. Thank you very much!

@jamis
jamis merged commit 4710b61 into mongodb:master Oct 21, 2026
85 checks passed
@jamis jamis added the bug Fixes a bug, with no new features or broken compatibility label Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Fixes a bug, with no new features or broken compatibility

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants