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
Stop byteslicing empty strings in breadcrumbs (#2574)
If we don't pass a message to the breadcrumb message, we default to an
empty string. However we can avoid byteslicing it, which allocates a new
empty string every time regardless.
```rb
require 'benchmark-memory'
MAX_MESSAGE_SIZE_IN_BYTES = 1024 * 8
def current(message)
(message || "").byteslice(0..MAX_MESSAGE_SIZE_IN_BYTES)
end
def updated(message)
message ? message.byteslice(0..MAX_MESSAGE_SIZE_IN_BYTES) : ""
end
Benchmark.memory do |x|
x.report("current") do
current(nil)
end
x.report("updated") do
updated(nil)
end
x.compare!
end
```
Calculating -------------------------------------
current 80.000 memsize ( 0.000 retained)
2.000 objects ( 0.000 retained)
1.000 strings ( 0.000 retained)
updated 0.000 memsize ( 0.000 retained)
0.000 objects ( 0.000 retained)
0.000 strings ( 0.000 retained)
Comparison:
updated: 0 allocated
current: 80 allocated - Infx more
0 commit comments