We are pleased to announce the open source release of the Fast JSON API gem geared towards Ruby on Rails applications.
Fast JSONAPI is aimed at providing all the major functionality that Active Model Serializer (AMS) provides, along with an emphasis on speed and performance by meeting a benchmark requirement of being 25 times faster than AMS. The gem also enforces performance testing as a discipline.
AMS is a great gem and fast_jsonapi was inspired by it when it comes to declaration syntax and features. AMS begins to slow down, however, when a model has one or more relationships. Compound documents, AKA sideloading, on those models makes AMS slow down further. Throw in a need for infinite scroll on the UI, and AMS’s slowness starts becoming visible to users.
Why optimize serialization?
JSON API serialization is often one of the slowest parts of many well implemented Rails APIs. Why not provide all the major functionality that AMS provides with greater speed?
- Declaration syntax similar to Active Model Serializer
- Support for belongs_to, has_many and has_one
- Support for compound documents (included)
- Optimized serialization of compound documents
- Instrumentation with Skylight integration (optional)
How do you write a serializer using Fast JSONAPI?
We like the familiar way Active Model Serializers lets us declare our serializers. Declaration syntax of fast_jsonapi is similar to AMS.
attributes :name, :year
belongs_to :owner, record_type: :user
How fast is it compared to Active Model Serializers?
Performance tests indicate a 25–40x speed gain over AMS, essentially making serialization time negligible on even fairly complex models. Performance gain is significant when the number of serialized records increases.
Difference in performance
Don’t believe us? You can run the benchmark tests for yourself. Refer to readme.
JSON API is the anti-bikeshedding tool.
We plan to add more features to the gem. We welcome suggestions, improvements, corrections and additional tests.