getsentry / sentry-native

Sentry SDK for C, C++ and native applications.
MIT License
405 stars 170 forks source link

Breadcrumbs should use more efficient ringbuffer #1006

Closed Swatinem closed 3 weeks ago

Swatinem commented 5 months ago

Adding a breadcrumb right now is using sentry__value_append_bounded to limit the number of breadcrumbs according to settings:

https://github.com/getsentry/sentry-native/blob/a05b260359246c75ccb594e86110a1fd326d04b3/src/sentry_core.c#L650-L651

However that internally does a costly memmove:

https://github.com/getsentry/sentry-native/blob/a05b260359246c75ccb594e86110a1fd326d04b3/src/sentry_value.c#L658

It would be nice to find a way to optimize this, for example by using a ringbuffer / linked list, or some other method to avoid doing a O(n) memmove every time when adding breadcrumbs that are at their maximum.