yosiat / panko_serializer

High Performance JSON Serialization for ActiveRecord & Ruby Objects
https://panko.dev
MIT License
592 stars 36 forks source link

Using ActiveRecord's pluck when possible #121

Open hboisgibault opened 2 years ago

hboisgibault commented 2 years ago

Some serializers or associations are simple enough to use ActiveRecord's pluck function to retrieve objects. pluck is much faster than retrieving objects with plain ActiveRecord.

I created a gem, Plucker Serializer, that uses this technique to improve performance. It also has built-in single object and collection caching. Benchmarks show that plucking can improve memory consumption and throughput, especially for large collections.

Adding custom type casting and using Oj::StringWriter like Panko does in addition with this technique could really boost performance in my opinion.