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 string allocations #284

Merged
merged 2 commits into from Jun 17, 2019
Merged

reduce string allocations #284

merged 2 commits into from Jun 17, 2019

Conversation

danmayer
Copy link
Owner

Fix inspired by new benchmark... We are using strings poorly a few places...Wondering if we can get JSON to use them better as well.

Prior to fix:

Allocated String Report
-----------------------------------
     40101  "^/Users/danmayer/projects/coverband/"
     40101  /Users/danmayer/projects/coverband/lib/coverband/utils/file_path_helper.rb:17

     30090  "data"
     20060  /Users/danmayer/.rvm/gems/ruby-2.3.5/gems/json-2.2.0/lib/json/common.rb:156
     10030  /Users/danmayer/projects/coverband/lib/coverband/adapters/redis_store.rb:99

     30090  "file_hash"
     20060  /Users/danmayer/.rvm/gems/ruby-2.3.5/gems/json-2.2.0/lib/json/common.rb:156
     10030  /Users/danmayer/projects/coverband/lib/coverband/adapters/redis_store.rb:99

     30090  "first_updated_at"
     20060  /Users/danmayer/.rvm/gems/ruby-2.3.5/gems/json-2.2.0/lib/json/common.rb:156
     10030  /Users/danmayer/projects/coverband/lib/coverband/adapters/redis_store.rb:99

     30090  "last_updated_at"
     20060  /Users/danmayer/.rvm/gems/ruby-2.3.5/gems/json-2.2.0/lib/json/common.rb:156
     10030  /Users/danmayer/projects/coverband/lib/coverband/adapters/redis_store.rb:99

     20060  "/Users/danmayer/projects/coverband"
     10030  /Users/danmayer/projects/coverband/lib/coverband/configuration.rb:146
     10030  /Users/danmayer/projects/coverband/lib/coverband/configuration.rb:152

     20060  "/Users/danmayer/projects/coverband/"
     10030  /Users/danmayer/projects/coverband/lib/coverband/configuration.rb:152
     10030  /Users/danmayer/projects/coverband/lib/coverband/utils/file_path_helper.rb:17

     20000  "4748375a25eb275a00c8d63c3d36cf90"
     10000  /Users/danmayer/.rvm/gems/ruby-2.3.5/gems/json-2.2.0/lib/json/common.rb:156
     10000  /Users/danmayer/projects/coverband/lib/coverband/adapters/redis_store.rb:99

     10030  "^"
     10030  /Users/danmayer/projects/coverband/lib/coverband/utils/file_path_helper.rb:17

After the fix:

Allocated String Report
-----------------------------------
     30090  "data"
     20060  /Users/danmayer/.rvm/gems/ruby-2.3.5/gems/json-2.2.0/lib/json/common.rb:156
     10030  /Users/danmayer/projects/coverband/lib/coverband/adapters/redis_store.rb:99

     30090  "file_hash"
     20060  /Users/danmayer/.rvm/gems/ruby-2.3.5/gems/json-2.2.0/lib/json/common.rb:156
     10030  /Users/danmayer/projects/coverband/lib/coverband/adapters/redis_store.rb:99

     30090  "first_updated_at"
     20060  /Users/danmayer/.rvm/gems/ruby-2.3.5/gems/json-2.2.0/lib/json/common.rb:156
     10030  /Users/danmayer/projects/coverband/lib/coverband/adapters/redis_store.rb:99

     30090  "last_updated_at"
     20060  /Users/danmayer/.rvm/gems/ruby-2.3.5/gems/json-2.2.0/lib/json/common.rb:156
     10030  /Users/danmayer/projects/coverband/lib/coverband/adapters/redis_store.rb:99

     30000  "4748375a25eb275a00c8d63c3d36cf90"
     20000  /Users/danmayer/projects/coverband/lib/coverband/adapters/redis_store.rb:99
     10000  /Users/danmayer/.rvm/gems/ruby-2.3.5/gems/json-2.2.0/lib/json/common.rb:156

       100  ""

@danmayer danmayer requested a review from kbaum June 11, 2019 22:05
Copy link
Collaborator

@kbaum kbaum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! I would have thought frozen string literal would allow for reuse of strings but i guess not.

Do you see a drop in total memory allocations too?

@danmayer
Copy link
Owner Author

yeah, it helps with total a bit as well... a nice but small win.

@danmayer danmayer merged commit b5ae5af into master Jun 17, 2019
@danmayer danmayer deleted the improve_string_allocations branch June 17, 2019 19:27
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