redwoodjs / redwood

The App Framework for Startups
https://redwoodjs.com
MIT License
17.28k stars 991 forks source link

`rw test api` Jest memory performance and benchmarks; api test leaking #4360

Open thedavidprice opened 2 years ago

thedavidprice commented 2 years ago

Background

Originally reported by @zygopleural here:

Web memory leak resolved and API memory leak mitigated via:

Because the API memory leak is not fully resolved, we want to benchmark and watch performance as well as keep this issue open for further work toward complete resolution.

This Issue uses the original reproduction with the new benchmarks.

related benchmark issue #4356

Expected behaviour

yarn redwood test should use ~ same heap size for each test unless the user has specifically done something wrong.

i.e. the heap size should not increase with each consecutive test or run (i.e. leak)

What currently happens

rw test web: The heap size is stable

Note: /web not tested in the reproduction and example below. But stability demonstrated here after config updates

rw test api: Even after mitigation in #4096 the heap size increases along with quantity of tests

Steps to reproduce

Option 1: Clone the Reproduction Repo

Note: if cloned, do check the version of Redwood packages, which might need upgrading for testing

Option 2. Create new app and run commands

1. Creat App

yarn create redwood-app --typescript test

2. Add some models to ./api/db/schema.prisma

Excuse the silly models, just something quick to generate tests.

model Man {
  id   String @id @default(cuid())
  name String
}

model Woman {
  id   String @id @default(cuid())
  name String
}

model Boy {
  id   String @id @default(cuid())
  name String
}

model Girl {
  id   String @id @default(cuid())
  name String
}

model Dog {
  id   String @id @default(cuid())
  name String
}

model Cat {
  id   String @id @default(cuid())
  name String
}

3. Generate some tests

yarn redwood generate sdl --crud man
yarn redwood generate sdl --crud woman
yarn redwood generate sdl --crud boy
yarn redwood generate sdl --crud girl
yarn redwood generate sdl --crud dog
yarn redwood generate sdl --crud cat

4. Run tests

yarn redwood test --logHeapUsage

Benchmarks as of v0.44

Initial test (watch mode)

Screen Shot 2022-02-02 at 5 19 38 PM

Second Run (watch

Screen Shot 2022-02-02 at 5 20 09 PM

mode)

Third Run (watch mode)

Screen Shot 2022-02-02 at 5 20 24 PM
callingmedic911 commented 2 years ago

EDIT: Moved to #4569

callingmedic911 commented 2 years ago

Just realised I was supposed to put details in https://github.com/redwoodjs/redwood/issues/4356 (Closed now). This issue is related to api. Moving my comment to a separate issue.

pi0neerpat commented 2 years ago

Brb downloading more RAM image