Skip to content

ref(value): track string length - #1968

Open
jpnurmi wants to merge 3 commits into
masterfrom
jpnurmi/ref/value-blob
Open

ref(value): track string length#1968
jpnurmi wants to merge 3 commits into
masterfrom
jpnurmi/ref/value-blob

Conversation

@jpnurmi

@jpnurmi jpnurmi commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Since sentry_value_new_string calls strlen + sentry_value_new_string_n anyway, we might as well store the length:

sentry_value_t
sentry_value_new_string(const char *value)
{
return value ? sentry_value_new_string_n(value, strlen(value))
: sentry_value_new_null();
}

This not only saves us from inefficiently calling strlen later, but also implicitly adds the capability to handle embedded NUL bytes for sentry_value_t-backed attachments in the future.

Scanning string lengths is not exactly the heaviest part of serialization, but the optimization does have a noticeable effect on large string-heavy event structures. For example, ~10% speedup for serializing a generated 230kb dummy event:

Before

tests/benchmark.py::test_benchmark_capture_event PASSED
Min 1.409ms, Max 1.409ms, Mean 1.409ms, Median 1.409ms, CPU 1.409ms

After

tests/benchmark.py::test_benchmark_capture_event PASSED
Min 1.231ms, Max 1.231ms, Mean 1.231ms, Median 1.231ms, CPU 1.231ms

benchmark_capture.cpp

See also:

Since `sentry_value_new_string` calls `strlen` + `sentry_value_new_string_n`
anyway, we might as well store the length. This does not only save us from
inefficiently calling `strlen` later, but also implicitly adds support for
embedded NUL bytes for presenting attachments (#1945).
Comment thread src/sentry_value.c Outdated
Comment thread src/sentry_json.c

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 50e9e3a. Configure here.

Comment thread src/sentry_json.c
@codecov

codecov Bot commented Aug 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.47368% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.05%. Comparing base (ff209d5) to head (50e9e3a).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1968      +/-   ##
==========================================
+ Coverage   75.98%   76.05%   +0.06%     
==========================================
  Files          94       94              
  Lines       22202    22234      +32     
  Branches     3938     3942       +4     
==========================================
+ Hits        16871    16909      +38     
+ Misses       4445     4438       -7     
- Partials      886      887       +1     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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