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

Memoize call_stack registry for same key entry #717

Merged
merged 1 commit into from
Oct 7, 2024

Conversation

vprigent
Copy link
Contributor

@vprigent vprigent commented Oct 6, 2024

With this simple trick, a local rails server with less than a dozen SQL queries using AR drastically reduces the amount of memory allocated by bullet.

before:

allocated memory by gem
-----------------------------------
    796102  activesupport-7.2.1
    726428  bullet/lib

after:

allocated memory by gem
-----------------------------------
    794350  activesupport-7.2.1
    313180  sprockets-4.2.1
    259688  activerecord-7.2.1
    204936  bullet/lib

Using the patched perf/benchmark.rb file to work with sqlite instead of mysql, I saw reproductible numbers:

main

Querying & Iterating 1000 Posts with 10000 Comments and 100 Users                            
user     system      total        real
14.503545   0.638605  15.142150 ( 15.201747)

patch

Querying & Iterating 1000 Posts with 10000 Comments and 100 Users

user     system      total        real
12.781415   0.664749  13.446164 ( 13.533855)

With this simple trick, a local rails server with less than a dozen SQL 
queries using AR drastically reduces the amount of memory allocated by 
bullet.
before:
```
allocated memory by gem
-----------------------------------
    796102  activesupport-7.2.1
    726428  bullet/lib
```

after:
```
allocated memory by gem
-----------------------------------
    794350  activesupport-7.2.1
    313180  sprockets-4.2.1
    259688  activerecord-7.2.1
    204936  bullet/lib
```

Using the patched perf/benchmark.rb file to work with sqlite instead of 
mysql, I saw reproductible numbers:

main
```
                                                                        
user     system      total        real
Querying & Iterating 1000 Posts with 10000 Comments and 100 Users       
14.503545   0.638605  15.142150 ( 15.201747)
```

patch
```
                                                                        
user     system      total        real
Querying & Iterating 1000 Posts with 10000 Comments and 100 Users       
12.781415   0.664749  13.446164 ( 13.533855)
```
@flyerhzm flyerhzm merged commit b6a3a8f into flyerhzm:main Oct 7, 2024
9 checks passed
@vprigent vprigent deleted the reduce-mem-allocation branch October 7, 2024 20:34
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.

2 participants