spree-performance
Installation
SKILL.md
Spree Performance
Spree 6 is API-first: the hot paths are Store API requests (catalog reads, cart writes, checkout) and background jobs. Most wins come from a handful of known hotspots, not generic Rails tuning.
Measure first
- Trace it. Add
gem 'spree_opentelemetry'and pointOTEL_EXPORTER_OTLP_ENDPOINTat a collector (Jaeger locally:docker run --rm -p 16686:16686 -p 4318:4318 jaegertracing/jaeger:latest). EverySpree::Workflowrun, each step, hook dispatch, event subscriber dispatch, webhook delivery and gateway call gets its own span alongside SQL and HTTP spans — e.g.carts.add_item,carts.complete process_payments. This tells you which step is slow without guessing. Custom workflows are traced automatically. - Count queries in a console or request spec:
ActiveRecord::Base.logger = Logger.new($stdout)and run the workflow directly. - Production APM (Skylight, Scout, New Relic, Datadog) all work; Datadog/Honeycomb/New Relic can also ingest the OTel traces.
Cart writes: the recalculation pipeline
Cart mutations (Spree::Carts::AddItem, UpsertItems, line item updates/removals and other cart edits) run Spree.cart_recalculate_workflow (Spree::Carts::Recalculate), which:
- refreshes totals via
Spree.cart_recalculate_totals_workflow(Spree::Carts::RecalculateTotals), - rebuilds delivery proposals (
cart.ensure_updated_fulfillments— delivery rate providers run here), - activates promotions (
set_promotion_contexthook, thenSpree::PromotionHandler::Cart), - runs
RecalculateTotalsagain to rebuild discounts and tax, - runs
after_recalculatehook handlers.