Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce the memory overhead of Bugsnag when session tracking isn't enabled #606

Merged
merged 2 commits into from Jul 23, 2020

Conversation

imjoehaines
Copy link
Member

@imjoehaines imjoehaines commented Jul 16, 2020

Goal

This PR requires the 'concurrent' gem only when it's needed, to help reduce the memory overhead of Bugsnag when session tracking isn't enabled (by ~4 MiB)

The shared SessionTracker instance is created on demand, so if an application doesn't use session tracking the 'concurrent' gem isn't required at all

This did have one drawback though — moving the require from the top level to the initialize method meant that the overhead from the concurrent gem was shifted into the first request, as that's where the first session will start. This had quite a big impact on response time (from ~10ms to ~70ms locally) so we now create the session tracker upfront. We do this after configuration has run so that we can avoid creating it if session tracking is disabled

Tests

The existing test suite should confirm this works

I've also manually tested that the SessionTracker isn't initialized when sessions are disabled (config.auto_capture_sessions = false)

Linked issues

Fixes #536

Review

For the submitter, initial self-review:

  • Commented on code changes inline explain the reasoning behind the approach
  • Reviewed the test cases added for completeness and possible points for discussion
  • A changelog entry was added for the goal of this pull request
  • Check the scope of the changeset - is everything in the diff required for the pull request?
  • This pull request is ready for:
    • Initial review of the intended approach, not yet feature complete
    • Structural review of the classes, functions, and properties modified
    • Final review

For the pull request reviewer(s), this changeset has been reviewed for:

  • Consistency across platforms for structures or concepts added or modified
  • Consistency between the changeset and the goal stated above
  • Internal consistency with the rest of the library - is there any overlap between existing interfaces and any which have been added?
  • Usage friction - is the proposed change in usage cumbersome or complicated?
  • Performance and complexity - are there any cases of unexpected O(n^3) when iterating, recursing, flat mapping, etc?
  • Concurrency concerns - if components are accessed asynchronously, what issues will arise
  • Thoroughness of added tests and any missing edge cases
  • Idiomatic use of the language

This helps reduce the memory overhead of Bugsnag when session tracking
isn't enabled by ~4 MiB
Create the session tracker if sessions are enabled to avoid the overhead
of creating it on the first request

By requiring the concurrent gem in the session tracker's initialize
method, we shifted the overhead from startup to the first request.
This caused the first request to go from ~10ms to ~70ms (in the Sinatra
example app run locally), which is quite alot of overhead
@imjoehaines imjoehaines marked this pull request as ready for review July 23, 2020 08:36
@imjoehaines imjoehaines merged commit 84aac9d into next Jul 23, 2020
@imjoehaines imjoehaines deleted the reduce-memory-overhead branch July 23, 2020 16:04
@imjoehaines imjoehaines mentioned this pull request Jul 24, 2020
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.

None yet

2 participants