Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qe-wasm: Fix consistent now() value #4650

Merged
merged 3 commits into from Jan 17, 2024
Merged

qe-wasm: Fix consistent now() value #4650

merged 3 commits into from Jan 17, 2024

Conversation

SevInf
Copy link
Contributor

@SevInf SevInf commented Jan 16, 2024

We introduced consitent request_now value in #3200,
however, we've opted out of thread local value if there is no active
tokio handle. This is problem for WASM build, since it does not have
use an actual tokio runtime.

Replacing handle check with LocalKey::try_with allows us to use task
local variable without the runtime, while still preserving fallback for
immediate value if task local is not set.

Fix prisma/team-orm#645

@SevInf SevInf added this to the 5.9.0 milestone Jan 16, 2024
We implemented introduced consitent `request_now` value in #3200,
however, we've opted out of thread local value if there is no active
tokio handle. This is problem for WASM build, since it does not have
use an actual tokio runtime.

Replacing handle check with `LocalKey::try_with` allows us to use task
local variable without the runtime, while still preserving fallback for
immediate value if task local is not set.

Fix prisma/team-orm#645
Copy link
Contributor

github-actions bot commented Jan 16, 2024

WASM Size

Engine This PR Base branch Diff
WASM 2.719MiB 2.719MiB 136.000B
WASM (gzip) 1.002MiB 1.002MiB 235.000B

Copy link

codspeed-hq bot commented Jan 16, 2024

CodSpeed Performance Report

Merging #4650 will not alter performance

Comparing fix/wasm-request-now (a0414be) with main (b35b06e)

Summary

✅ 11 untouched benchmarks

Copy link
Contributor

github-actions bot commented Jan 16, 2024

✅ WASM query-engine: no benchmarks have regressed

Full benchmark report
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/bench?schema=imdb_bench&sslmode=disable" \
node --experimental-wasm-modules query-engine/driver-adapters/executor/dist/bench.mjs
cpu: AMD EPYC 7763 64-Core Processor
runtime: node v18.19.0 (x64-linux)

benchmark                   time (avg)             (min … max)       p75       p99      p995
-------------------------------------------------------------- -----------------------------
• movies.findMany() (all - 25000)
-------------------------------------------------------------- -----------------------------
Web Assembly: Baseline  301.85 ms/iter (299.34 ms … 318.17 ms) 300.89 ms 318.17 ms 318.17 ms
Web Assembly: Latest    304.86 ms/iter (301.72 ms … 312.99 ms) 307.36 ms 312.99 ms 312.99 ms
Web Assembly: Current   303.05 ms/iter (300.93 ms … 315.67 ms) 302.33 ms 315.67 ms 315.67 ms
Node API: Current       233.77 ms/iter (224.25 ms … 243.43 ms) 237.74 ms 243.43 ms 243.43 ms

summary for movies.findMany() (all - 25000)
  Web Assembly: Current
   1.3x slower than Node API: Current
   1x faster than Web Assembly: Baseline
   1.01x faster than Web Assembly: Latest

• movies.findMany({ take: 2000 })
-------------------------------------------------------------- -----------------------------
Web Assembly: Baseline   12.94 ms/iter   (11.88 ms … 22.74 ms)  12.39 ms  22.74 ms  22.74 ms
Web Assembly: Latest     12.52 ms/iter      (11.92 ms … 17 ms)   12.3 ms     17 ms     17 ms
Web Assembly: Current    12.53 ms/iter   (12.11 ms … 17.69 ms)   12.3 ms  17.69 ms  17.69 ms
Node API: Current         9.47 ms/iter        (9 ms … 9.91 ms)   9.64 ms   9.91 ms   9.91 ms

summary for movies.findMany({ take: 2000 })
  Web Assembly: Current
   1.32x slower than Node API: Current
   1x faster than Web Assembly: Latest
   1.03x faster than Web Assembly: Baseline

• movies.findMany({ where: {...}, take: 2000 })
-------------------------------------------------------------- -----------------------------
Web Assembly: Baseline    2.08 ms/iter     (1.85 ms … 3.56 ms)   2.03 ms   3.43 ms   3.54 ms
Web Assembly: Latest      2.09 ms/iter     (1.86 ms … 3.58 ms)   2.02 ms   3.44 ms   3.53 ms
Web Assembly: Current     2.07 ms/iter     (1.87 ms … 3.46 ms)   1.99 ms   3.43 ms   3.45 ms
Node API: Current         1.53 ms/iter     (1.45 ms … 1.91 ms)   1.56 ms   1.74 ms   1.77 ms

summary for movies.findMany({ where: {...}, take: 2000 })
  Web Assembly: Current
   1.35x slower than Node API: Current
   1x faster than Web Assembly: Baseline
   1.01x faster than Web Assembly: Latest

• movies.findMany({ include: { cast: true } take: 2000 }) (m2m)
-------------------------------------------------------------- -----------------------------
Web Assembly: Baseline   12.18 ms/iter   (11.87 ms … 13.75 ms)  12.22 ms  13.75 ms  13.75 ms
Web Assembly: Latest     12.22 ms/iter   (11.91 ms … 13.68 ms)  12.27 ms  13.68 ms  13.68 ms
Web Assembly: Current    12.39 ms/iter   (12.12 ms … 19.75 ms)  12.28 ms  19.75 ms  19.75 ms
Node API: Current         9.45 ms/iter    (8.94 ms … 11.38 ms)   9.58 ms  11.38 ms  11.38 ms

summary for movies.findMany({ include: { cast: true } take: 2000 }) (m2m)
  Web Assembly: Current
   1.31x slower than Node API: Current
   1.02x slower than Web Assembly: Baseline
   1.01x slower than Web Assembly: Latest

• movies.findMany({ where: {...}, include: { cast: true } take: 2000 }) (m2m)
-------------------------------------------------------------- -----------------------------
Web Assembly: Baseline    1.94 ms/iter     (1.83 ms … 3.21 ms)   1.93 ms   3.09 ms   3.14 ms
Web Assembly: Latest      1.97 ms/iter     (1.85 ms … 4.54 ms)   1.94 ms   3.18 ms    3.2 ms
Web Assembly: Current     1.94 ms/iter      (1.84 ms … 3.2 ms)   1.92 ms   3.06 ms   3.08 ms
Node API: Current         1.58 ms/iter     (1.45 ms … 2.74 ms)   1.56 ms   2.41 ms   2.55 ms

summary for movies.findMany({ where: {...}, include: { cast: true } take: 2000 }) (m2m)
  Web Assembly: Current
   1.23x slower than Node API: Current
   1x faster than Web Assembly: Baseline
   1.01x faster than Web Assembly: Latest

• movies.findMany({ take: 2000, include: { cast: { include: { person: true } } } })
-------------------------------------------------------------- -----------------------------
Web Assembly: Baseline   12.17 ms/iter   (11.85 ms … 15.72 ms)   12.2 ms  15.72 ms  15.72 ms
Web Assembly: Latest     12.32 ms/iter   (12.11 ms … 16.11 ms)  12.27 ms  16.11 ms  16.11 ms
Web Assembly: Current     12.2 ms/iter   (11.91 ms … 13.16 ms)  12.25 ms  13.16 ms  13.16 ms
Node API: Current          9.4 ms/iter    (9.12 ms … 11.25 ms)   9.39 ms  11.25 ms  11.25 ms

summary for movies.findMany({ take: 2000, include: { cast: { include: { person: true } } } })
  Web Assembly: Current
   1.3x slower than Node API: Current
   1x faster than Web Assembly: Baseline
   1.01x faster than Web Assembly: Latest

• movie.findMany({ where: { ... }, take: 2000, include: { cast: { include: { person: true } } } })
-------------------------------------------------------------- -----------------------------
Web Assembly: Baseline    1.91 ms/iter      (1.82 ms … 3.1 ms)    1.9 ms   2.68 ms   3.03 ms
Web Assembly: Latest      1.92 ms/iter     (1.83 ms … 2.78 ms)    1.9 ms   2.63 ms   2.72 ms
Web Assembly: Current     1.96 ms/iter     (1.84 ms … 3.32 ms)   1.93 ms   3.25 ms    3.3 ms
Node API: Current         1.58 ms/iter      (1.5 ms … 1.79 ms)   1.59 ms   1.75 ms   1.77 ms

summary for movie.findMany({ where: { ... }, take: 2000, include: { cast: { include: { person: true } } } })
  Web Assembly: Current
   1.24x slower than Node API: Current
   1.02x slower than Web Assembly: Baseline
   1.02x slower than Web Assembly: Latest

• movie.findMany({ where: { reviews: { author: { ... } }, take: 100 }) (to-many -> to-one)
-------------------------------------------------------------- -----------------------------
Web Assembly: Baseline  927.36 µs/iter   (855.93 µs … 2.66 ms) 924.49 µs   1.46 ms   1.53 ms
Web Assembly: Latest    927.21 µs/iter   (860.16 µs … 1.55 ms)    919 µs   1.49 ms   1.53 ms
Web Assembly: Current      943 µs/iter   (861.69 µs … 3.03 ms) 925.29 µs   1.54 ms   1.59 ms
Node API: Current       849.36 µs/iter  (780.7 µs … 940.05 µs) 861.93 µs 917.17 µs 928.47 µs

summary for movie.findMany({ where: { reviews: { author: { ... } }, take: 100 }) (to-many -> to-one)
  Web Assembly: Current
   1.11x slower than Node API: Current
   1.02x slower than Web Assembly: Latest
   1.02x slower than Web Assembly: Baseline

• movie.findMany({ where: { cast: { person: { ... } }, take: 100 }) (m2m -> to-one)
-------------------------------------------------------------- -----------------------------
Web Assembly: Baseline  937.52 µs/iter   (887.45 µs … 1.48 ms) 933.74 µs   1.36 ms   1.42 ms
Web Assembly: Latest    908.11 µs/iter   (856.98 µs … 1.44 ms)  909.5 µs   1.25 ms   1.41 ms
Web Assembly: Current    911.5 µs/iter   (867.97 µs … 1.31 ms) 912.74 µs   1.22 ms   1.25 ms
Node API: Current       847.61 µs/iter   (813.24 µs … 3.53 ms) 855.25 µs 935.39 µs   1.02 ms

summary for movie.findMany({ where: { cast: { person: { ... } }, take: 100 }) (m2m -> to-one)
  Web Assembly: Current
   1.08x slower than Node API: Current
   1x faster than Web Assembly: Latest
   1.03x faster than Web Assembly: Baseline

After changes in a0414be

@SevInf SevInf marked this pull request as ready for review January 16, 2024 17:03
@SevInf SevInf requested a review from a team as a code owner January 16, 2024 17:03
@SevInf SevInf requested review from miguelff and Druue and removed request for a team January 16, 2024 17:03
Copy link
Collaborator

@miguelff miguelff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

query-engine/core/src/executor/request_context.rs Outdated Show resolved Hide resolved
@SevInf SevInf merged commit 71726cc into main Jan 17, 2024
114 checks passed
@SevInf SevInf deleted the fix/wasm-request-now branch January 17, 2024 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants