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

Better benchmarks using existing method #97

Conversation

NullVoxPopuli
Copy link

I'm not a huge fan of AMS, but it's a diservice to claim 25x when AMS, by default is underscored (because ruby / ActiveRecord is underscored, so telling to to perform additional transformations is cheating a bit).

Additionally, here are results with and without oj_mimic_json:

with

bundle exec rspec ./spec/lib/object_serializer_performance_spec.rb[1:3:4]
Run options: include {:ids=>{"./spec/lib/object_serializer_performance_spec.rb"=>["1:3:4"]}}

Serialize to JSON string 1000 with includes and meta
Serializer             Records    Time       Speed Up
Fast serializer        1000       28.13 ms  
AMS serializer         1000       439.81 ms  15.63x ✘
jsonapi-rb serializer  1000       98.9 ms    3.52x ✔
jsonapi-serializers    1000       133.2 ms   4.73x ✔

Serialize to Ruby Hash 1000 with includes and meta
Serializer             Records    Time       Speed Up
Fast serializer        1000       24.31 ms  
AMS serializer         1000       406.64 ms  16.73x ✘
jsonapi-rb serializer  1000       95.43 ms   3.93x ✔
jsonapi-serializers    1000       126.03 ms  5.18x ✔

without

bundle exec rspec ./spec/lib/object_serializer_performance_spec.rb[1:3:4]
Run options: include {:ids=>{"./spec/lib/object_serializer_performance_spec.rb"=>["1:3:4"]}}

Serialize to JSON string 1000 with includes and meta
Serializer             Records    Time       Speed Up
Fast serializer        1000       35.42 ms  
AMS serializer         1000       453.29 ms  12.8x ✘
jsonapi-rb serializer  1000       99.6 ms    2.81x ✔
jsonapi-serializers    1000       131.6 ms   3.72x ✔

Serialize to Ruby Hash 1000 with includes and meta
Serializer             Records    Time       Speed Up
Fast serializer        1000       23.02 ms  
AMS serializer         1000       428.47 ms  18.61x ✘
jsonapi-rb serializer  1000       94.08 ms   4.09x ✔
jsonapi-serializers    1000       127.92 ms  5.56x ✔

@shishirmk
Copy link
Collaborator

The 25x speed improvement was something we observed in our current master branch. if we change the key_transform to :unaltered in our current master branch the benchmark numbers look like this

Serialize to Ruby Hash 250 with includes and meta
Serializer      Records    Time
AMS serializer  250        109.67 ms
Fast serializer 250        3.98 ms

Serialize to Ruby Hash 1000 with includes and meta
Serializer      Records    Time
AMS serializer  1000       404.87 ms
Fast serializer 1000       16.02 ms

As you can see these are still showing more than 25x improvement.

Let's ignore the JSON String serialization comparison as both fast_jsonapi and AMS really just produce the ruby hash. This ruby hash is serialized to a string later with a JSON engine like (OJ, YAJL, etc). I have said this before in #51 . This effectively would rule out any effects of Oj.optimize_rails or oj_mimic_json on the benchmark numbers

The dev branch currently shows 15x to 35x improvement depending on features used and number of records being serialized.

Here are the benchmark numbers when AMS key_transform is set to :unaltered in our dev branch. Here is the git diff of minor changes i made

Serialize to Ruby Hash 25 records
Serializer             Records    Time       Speed Up
Fast serializer        25         0.26 ms
AMS serializer         25         8.58 ms    32.9x ✔
jsonapi-rb serializer  25         0.98 ms    3.77x ✔
jsonapi-serializers    25         1.13 ms    4.35x ✔

Serialize to Ruby Hash 250 records
Serializer             Records    Time       Speed Up
Fast serializer        250        2.32 ms
AMS serializer         250        72.35 ms   31.23x ✔
jsonapi-rb serializer  250        7.85 ms    3.39x ✔
jsonapi-serializers    250        6.75 ms    2.92x ✔

Serialize to Ruby Hash 1000 records
Serializer             Records    Time       Speed Up
Fast serializer        1000       9.08 ms
AMS serializer         1000       291.21 ms  32.09x ✔
jsonapi-rb serializer  1000       32.48 ms   3.58x ✔
jsonapi-serializers    1000       27.5 ms    3.03x ✔

Serialize to Ruby Hash 25 with includes and meta
Serializer             Records    Time       Speed Up
Fast serializer        25         0.59 ms
AMS serializer         25         12.47 ms   20.98x ✘
jsonapi-rb serializer  25         4.06 ms    6.83x ✔
jsonapi-serializers    25         2.92 ms    4.92x ✔

Serialize to Ruby Hash 250 with includes and meta
Serializer             Records    Time       Speed Up
Fast serializer        250        5.49 ms
AMS serializer         250        105.43 ms  19.19x ✘
jsonapi-rb serializer  250        19.7 ms    3.59x ✔
jsonapi-serializers    250        24.73 ms   4.5x ✔

Serialize to Ruby Hash 1000 with includes and meta
Serializer             Records    Time       Speed Up
Fast serializer        1000       22.64 ms
AMS serializer         1000       421.55 ms  18.62x ✘
jsonapi-rb serializer  1000       82.29 ms   3.63x ✔
jsonapi-serializers    1000       93.54 ms   4.13x ✔

Serialize to Ruby Hash 25 with polymorphic has_many
Serializer             Records    Time       Speed Up
Fast serializer        25         0.19 ms
AMS serializer         25         6.99 ms    37.47x ✔
jsonapi-rb serializer  25         0.72 ms    3.86x ✔
jsonapi-serializers    25         0.84 ms    4.48x ✔

Serialize to Ruby Hash 250 with polymorphic has_many
Serializer             Records    Time       Speed Up
Fast serializer        250        1.51 ms
AMS serializer         250        53.04 ms   35.24x ✔
jsonapi-rb serializer  250        5.35 ms    3.55x ✔
jsonapi-serializers    250        3.81 ms    2.53x ✔

Serialize to Ruby Hash 1000 with polymorphic has_many
Serializer             Records    Time       Speed Up
Fast serializer        1000       6.06 ms
AMS serializer         1000       191.03 ms  31.51x ✔
jsonapi-rb serializer  1000       22.43 ms   3.7x ✔
jsonapi-serializers    1000       15.37 ms   2.54x ✔

@NullVoxPopuli I think we have covered extensively about the benchmark numbers in several issues, pull request comments, and the performance write up that we have added to the repo. We have said repeatedly the goal of these tests is only to make developers aware of the performance implications of the features they are helping us build.

I would be happy to accept the pull request if it changes the AMS key_transform to :unaltered and adds a separate performance test comparing the performance numbers when both serializers have key_transform set to :camel_case or some other similar transform.

shishirmk pushed a commit that referenced this pull request Feb 28, 2018
* add hash benchmarking to performance tests

* Add missing attribute in README example

* Disable GC before doing performance test

* Enable oj to AM for fair benchmark test

* add information on performance methodology

* add oss metadata

* Make an error that demonstrates [Issue

* Simple RSpec test that fails with a non-empty string but passes with a
non-empty symbol
* To run the test, rspec spec/lib/object_serializer_spec.rb

* Map includes to symbols if they are provided as strings

* Includes would fail with an ArgumentError unless they were explicitly
provided as symbols (see #97)
* This is solved by mapping the strings to symbols in the
ObjectSerializer initializer
* No real impact on performance here
@shishirmk
Copy link
Collaborator

Closing this as there is no response

@shishirmk shishirmk closed this Mar 13, 2018
andyjeffries pushed a commit to andyjeffries/fast_jsonapi that referenced this pull request May 25, 2018
* add hash benchmarking to performance tests

* Add missing attribute in README example

* Disable GC before doing performance test

* Enable oj to AM for fair benchmark test

* add information on performance methodology

* add oss metadata

* Make an error that demonstrates [Issue

* Simple RSpec test that fails with a non-empty string but passes with a
non-empty symbol
* To run the test, rspec spec/lib/object_serializer_spec.rb

* Map includes to symbols if they are provided as strings

* Includes would fail with an ArgumentError unless they were explicitly
provided as symbols (see Netflix#97)
* This is solved by mapping the strings to symbols in the
ObjectSerializer initializer
* No real impact on performance here
andyjeffries pushed a commit to andyjeffries/fast_jsonapi that referenced this pull request May 25, 2018
* add hash benchmarking to performance tests

* Add missing attribute in README example

* Disable GC before doing performance test

* Enable oj to AM for fair benchmark test

* add information on performance methodology

* add oss metadata

* Make an error that demonstrates [Issue

* Simple RSpec test that fails with a non-empty string but passes with a
non-empty symbol
* To run the test, rspec spec/lib/object_serializer_spec.rb

* Map includes to symbols if they are provided as strings

* Includes would fail with an ArgumentError unless they were explicitly
provided as symbols (see Netflix#97)
* This is solved by mapping the strings to symbols in the
ObjectSerializer initializer
* No real impact on performance here
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