Gem Netflix 發佈的 JSON Serializer,比 Active Model Serializer 的快二十多倍

Aiken00 · March 03, 2018 · Last by lulalala replied at March 07, 2018 · 3146 hits

Fast JSON API

A lightning fast JSON:API serializer for Ruby Objects.

Performance Comparison

We compare serialization times with Active Model Serializer as part of RSpec performance tests included on this library. We want to ensure that with every change on this library, serialization time is at least 25 times faster than Active Model Serializers on up to current benchmark of 1000 records. Please read the performance document for any questions related to methodology.

Benchmark times for 250 records

$ rspec
Active Model Serializer serialized 250 records in 138.71 ms
Fast JSON API serialized 250 records in 3.01 ms

https://github.com/Netflix/fast_jsonapi

We compare serialization times with Active Model Serializer as part of RSpec performance tests included on this library. We want to ensure that with every change on this library, serialization time is at least 25 times faster than Active Model Serializers on up to current benchmark of 1000 records. Please read the performance document for any questions related to methodology.

Reply to sandy_xu

感謝指正

原本的是根據它的 benchmarking 結果計算出來的 現在跟官方說的,修改了標題了

Reply to Aiken00

其实没有问题吧,至少 25 倍可以快 40 多倍 并不矛盾。

支持 JSON:API 规范的库里 AMS 一直都是速度垫底的,也不是功能最强大的。

给 AMS 底层换 oj benchmark 都能快三倍了,标准库的做法很保守

Any reason why this isn't default? What are the trade offs?

Reply to ksec

简约 直接 没有太多可以更改的设置 只支持 jsonapi 规格 简单来说就是牺牲功能来增加速度

Rails 為了怕開發者受傷,做了很多保護開發者的事情 https://github.com/rails/rails/blob/64c88fb5d2caf3c34742a07394ac68b8377c4936/activesupport/lib/active_support/core_ext/object/json.rb

這造成有幾個 edge case 是 ActiveSupport::JSON::Encode 會過但是用 oj 時不會過。但是一般人應該沒在擔心這些 edge case 的。想必 netflix 的版本更不擔心。

You need to Sign in before reply, if you don't have an account, please Sign up first.