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

  1. Trace it. Add gem 'spree_opentelemetry' and point OTEL_EXPORTER_OTLP_ENDPOINT at a collector (Jaeger locally: docker run --rm -p 16686:16686 -p 4318:4318 jaegertracing/jaeger:latest). Every Spree::Workflow run, 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.
  2. Count queries in a console or request spec: ActiveRecord::Base.logger = Logger.new($stdout) and run the workflow directly.
  3. 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:

  1. refreshes totals via Spree.cart_recalculate_totals_workflow (Spree::Carts::RecalculateTotals),
  2. rebuilds delivery proposals (cart.ensure_updated_fulfillments — delivery rate providers run here),
  3. activates promotions (set_promotion_context hook, then Spree::PromotionHandler::Cart),
  4. runs RecalculateTotals again to rebuild discounts and tax,
  5. runs after_recalculate hook handlers.
Installs
277
GitHub Stars
10
First Seen
Jun 11, 2026