Performance: Serializers (Active Model Serializers)
MEDIUM IMPACT
This affects the server response time and the size of JSON payloads sent to the browser, impacting page load speed and interaction readiness.
class UserSerializer < ActiveModel::Serializer
attributes :id, :name, :email
endclass UserSerializer < ActiveModel::Serializer
attributes :id, :name, :email, :created_at, :updated_at, :password_digest, :session_token
end| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Serializing all model attributes including sensitive data | N/A (server-side) | N/A | N/A | [X] Bad |
| Serializing only needed attributes | N/A (server-side) | N/A | N/A | [OK] Good |
| Not eager loading associations causing N+1 queries | N/A (server-side) | N/A | N/A | [X] Bad |
| Eager loading associations before serialization | N/A (server-side) | N/A | N/A | [OK] Good |