volroom

volroom

Hello, we’ve been investigating the performance of one of our queries - basically it’s used to list products and categories like you’d see on an e-commerce site. On our dev environment it takes roughly 10s, and with tracing I can see that the first ~2 seconds are spent fetching the main body of data (DB queries etc). Then at the end Absinthe.Phase.Document.Execution.Resolution takes up around 6 to 7s and Absinthe.Phase.Document.Result takes around 500ms.

We’re a bit surprised that the bulk of the request time is spent resolving the fields - in order to check that our resolvers aren’t the problem, we moved all the processing and logic into the context function, so that the fields are just resolved by Map.get/2

Is it just expected for the resolution phase to take this long? It is a big query to be fair (if I prettify the response it takes up 87,056 lines)

Showing Posts 1 to 5

FlyingNoodle

FlyingNoodle

I’m not an expert on absinthe or graphql but from my experience field resolution always takes the most time.

If I put an expensive operation in a field resolver it multiplies when resolving this field in 100 entities.

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Hey there @volroom to sanity check a few things here, you’re saying that all of the actual IO to load data has already been done?

Some additional context that would be helpful.

  1. How big is the query itself? Can you share it?

  2. How big is the result JSON (in bytes)

  3. Are you using the Persistent Term backend? This helps a lot with memory efficiency which can help.

volroom

volroom OP

Hi @benwilson512

Yes, we moved all IO & data wrangling right to the beginning.

Here’s the query for context:

query Categories($id: UUID, $slug: String, $fulfillmentDatetime: UTCTimestamp, $fulfillmentType: FulfillmentType) {
  store(id: $id, slug: $slug) {
    categories(
      fulfillmentDatetime: $fulfillmentDatetime
      fulfillmentType: $fulfillmentType
    ) {
      id
      name
      description
      products {
        id
        allergens
        calorieData {
          caloriesPerServing
        }
        defaultVariantId
        description
        images {
          original
          standard
          thumb
        }
        inStock
        limit
        dietaryRequirements
        modifierGroups {
          id
          name
          maximum
          minimum
          modifiers {
            id
            allergens
            image {
              original
              standard
              thumb
            }
            inStock
            name
            price {
              base
              discounted
              reduction
            }
            restrictions {
              alcoholic
            }
          }
        }
        name
        options {
          name
          values
        }
        pricing {
          lowestVariant {
            base
            discounted
            reduction
          }
          maximum {
            base
            discounted
            reduction
          }
          minimum {
            base
            discounted
            reduction
          }
        }
        promotion {
          amount
          discountType
        }
        quickAddAllowed
        seoDescription
        slug
        restrictions {
          alcoholic
        }
        variants {
          allergens
          id
          inStock
          name
          limit
          pricing {
            absolute {
              base
              discounted
              reduction
            }
            relative {
              base
              discounted
              reduction
            }
          }
          restrictions {
            alcoholic
          }
          options {
            name
            value
          }
        }
      }
    }
  }
}

Which returns an output of 3071.81KB

We aren’t using the Persistent Term backend, will give that a go.

Worth pointing out that the times I quoted in my OP are on a very CPU-constrained test environment, not production.

volroom

volroom OP

Persistent Term doesn’t seem to have had a significant impact

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

3 megs is a TON of data to ship via GraphQL. Unlike just shipping regular JSON every return value is type checked against the schema, errors are tracked at the node level, and so on. While there are hypothetical optimizations I have wanted to do in the resolution phase they’d involve a level of refactor I just haven’t had time for to date.

Overall I’d find a way to maybe paginate products if that’s the big field or something.

— All posts loaded —

Where Next? Top

Trending in Questions Top

thiagogsr
** (ArgumentError) expected :max_attempts to be a positive integer, got: {:@, [line: 10, column: 19], [{:max_attempts, [line: 10, column:...
New
RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews