4 ms·
If you are using Rails and ActiveModelSerializers, I wrote a gem to take your serializer definition and build the whole JSON result in Postgres: [0] It hasn't g
by pjungwir 5y ago
If you are using Rails and ActiveModelSerializers, I wrote a gem to take your serializer definition and build the whole JSON result in Postgres: [0] It hasn't gotten much use, but I know at least one company that has used it to get 100x performance boosts on #index endpoints.
It generates jsonapi right now, since that is standard for Ember projects, but it'd be pretty easy to add an adapter for some other format.
[0] https://github.com/pjungwir/active_model_serializers_pg https://github.com/pjungwir/active_model_serializers_pg
- davidwparker 5y agoHow does it compare in terms of performance to https://github.com/jsonapi-serializer/jsonapi-serializer https://github.com/jsonapi-serializer/jsonapi-serializer (a fork of Fast JSON API out of Netflix, which wasn't being maintained)?
- jrochkind1 5y agowow, that's really neat, this could solve a problem I have, bookmarking!
- karmajunkie 5y agoI've done this manually as an optimization on particularly hairy (and large) reports, retrieving a JSON string from the postgres query, then interpolating it into a boilerplate string response. In a few, particularly pathological cases (that nonetheless were fairly common to run into in prod), the response time of the endpoint went from literal minutes to a few hundred milliseconds on a test server with unlimited response timeout (prod would have timed out after 60s). Most of the performance increase came from not requiring Ruby to parse strings into fat objects, then turn it back into a long string to go out the wire.