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

Aiken00 · 2018年03月03日 · 最后由 lulalala 回复于 2018年03月07日 · 2611 次阅读

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.

sandy_xu 回复

感謝指正

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

Aiken00 回复

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

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

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

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

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 的版本更不擔心。

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册