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 number of created objects in Hash#as_json #38197

Merged
merged 1 commit into from Jan 10, 2020

Conversation

@apauly
Copy link
Contributor

apauly commented Jan 9, 2020

Summary

Reduce the number of objects allocated in Hash#as_json by 2 for every time Hash#as_json is being called.

Other Information

In order to benchmark this, I wrote a small script
-> https://gist.github.com/apauly/3f547f06e83b66e4187e48519b426464

The difference is of course highly coupled to the actual size of the hash. The output of the gist will look something like this:

>> compare build_random_hash(1, 1)
Object count after patch: 3
Object count before patch: 7

>> compare build_random_hash(1, 10)
Object count after patch: 30
Object count before patch: 60

>> compare build_random_hash(3, 3)
Object count after patch: 91
Object count before patch: 156

>> compare build_random_hash(5, 5)
Object count after patch: 8591
Object count before patch: 14058
@rails-bot rails-bot bot added the activesupport label Jan 9, 2020
@kamipo kamipo merged commit d51bc46 into rails:master Jan 10, 2020
2 checks passed
2 checks passed
build
Details
buildkite/rails Build #66302 passed (15 minutes, 49 seconds)
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.