You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reduce memory allocations during exception capture with zero-risk changes
that preserve identical behavior:
Backtrace::Line.parse:
- Use indexed regex captures (match[1]) instead of .to_a destructuring,
avoiding intermediate array allocation
- Add end_with? guard before .sub! for .class extension — skips string
allocation on non-JRuby (99.9% of cases)
- Use match? instead of =~ in #in_app to avoid MatchData allocation
- Add nil guard for file in #in_app
StacktraceInterface::Frame:
- Remove stored @project_root/@strip_backtrace_load_path ivars (passed as
args to compute_filename instead) — fewer entries in Interface#to_h
- Use byteslice instead of [] for filename prefix stripping
- Replace chomp(File::SEPARATOR) with end_with? check to avoid allocation
- Inline under_project_root? to eliminate method call overhead
StacktraceBuilder#build:
- Replace select + reverse + map + compact chain with single reverse while
loop, eliminating 3 intermediate array allocations
RequestInterface:
- Use delete_prefix instead of regex sub for HTTP_ prefix removal
- Replace key.upcase != key with key.match?(LOWERCASE_PATTERN) to avoid
allocating an upcased string for every Rack env entry
- Cache Rack version check to avoid repeated Gem::Version comparisons
0 commit comments