graphql-tools icon indicating copy to clipboard operation
graphql-tools copied to clipboard

Performance Issues because of AbortSignal (Execution Cancellation Plugin)

Open pozylon opened this issue 10 months ago • 5 comments

This line here likely makes yoga 10x slower because it almost spends all of it's time adding event listeners when an AbortSignal is provided through the execution context. I just wanted to share my finding here and I'm currently looking for a solution and I don't have an idea yet how to fix that...

https://github.com/ardatan/graphql-tools/blob/5ecdb9dc6f119189892aeb9f284a1fae306b7ff9/packages/executor/src/execution/promiseForObject.ts#L18

Maybe it's some kind of regression because of this commit here: https://github.com/ardatan/graphql-tools/commit/020b9e47b51f9847bf915d ?

Bildschirmfoto 2024-12-21 um 17 22 51 Bildschirmfoto 2024-12-21 um 17 23 15

pozylon avatar Dec 21 '24 16:12 pozylon

Of course i'm doing some artifical request here but still the effect is dramatic the more objects there are in the response:

Response time of that API Request above with useExecutionCancellation(): ~4000ms Response time of that same API Request without useExecutionCancellation(): ~900ms

Bildschirmfoto 2024-12-21 um 17 41 21

pozylon avatar Dec 21 '24 16:12 pozylon

Could you test with the following alpha? @graphql-tools/executor | 1.3.10-alpha-20241224080220-7cec9a36c8869567ca685def6970f80d29f8b7f5

ardatan avatar Dec 24 '24 08:12 ardatan

Bildschirmfoto 2024-12-27 um 17 03 06 Bildschirmfoto 2024-12-27 um 17 03 58

much better !!

pozylon avatar Dec 27 '24 16:12 pozylon

This shaves off another few milliseconds btw:

 //const promises = Promise.all(Object.entries(object).map(async ([key, value]) => {
  //    resolvedObject[key] = await value;
  //}));
  const promises = Promise.all(Object.keys(object).map(async (key) => {
      resolvedObject[key] = await object[key];
  }))

pozylon avatar Dec 27 '24 16:12 pozylon

We did a refactor there recently. Could you try it again and let us know if the performance issue persists. Also cc @enisdenjo

ardatan avatar Mar 13 '25 11:03 ardatan

Closing due to the inactivity. If the issue persisted, we can always re-open the issue! Thanks for the collaboration.

ardatan avatar Jul 17 '25 00:07 ardatan