Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stop byteslicing empty strings in breadcrumbs
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
- Loading branch information