Skip to content

Commit

Permalink
test: add benchmark for select querybuilder (typeorm#8955)
Browse files Browse the repository at this point in the history
Motivation: the query builder (and within it, replacePropertyNames and
associated functions) is pretty CPU intensive. For our workload, it's
one of the hottest functions in our entire stack.

While improved in typeorm#4760,
There are still outstanding issues relating to perf e.g. typeorm#3857

As we all know though, the first step in optimization is to measure
systematically ;)

https://wiki.c2.com/?ProfileBeforeOptimizing

On my machine, this benchmark runs in ~3500ms or about 0.35ms/query.
This tells us there's a way to go - on my stack, that's about 1/3 of a
typical query's latency!
  • Loading branch information
draaglom authored and frangz committed Nov 14, 2022
1 parent 330a751 commit bda2c2c
Show file tree
Hide file tree
Showing 11 changed files with 472 additions and 0 deletions.
38 changes: 38 additions & 0 deletions test/benchmark/multiple-joins-querybuilder/entity/Eight.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Entity } from "../../../../src/decorator/entity/Entity"
import { PrimaryGeneratedColumn } from "../../../../src/decorator/columns/PrimaryGeneratedColumn"
import { Column } from "../../../../src/decorator/columns/Column"
import { One } from "./One"
import { ManyToOne } from "../../../../src"

@Entity()
export class Eight {
@PrimaryGeneratedColumn()
id: number

@ManyToOne((type) => One)
one: One

@Column({ type: "text" })
aaaaa: string

@Column({ type: "text" })
bbbbb: string

@Column({ type: "text" })
ccccc: string

@Column({ type: "text" })
ddddd: string

@Column({ type: "text" })
eeeee: string

@Column({ type: "text" })
fffff: string

@Column({ type: "text" })
ggggg: string

@Column({ type: "text" })
hhhhh: string
}
38 changes: 38 additions & 0 deletions test/benchmark/multiple-joins-querybuilder/entity/Five.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Entity } from "../../../../src/decorator/entity/Entity"
import { PrimaryGeneratedColumn } from "../../../../src/decorator/columns/PrimaryGeneratedColumn"
import { Column } from "../../../../src/decorator/columns/Column"
import { One } from "./One"
import { ManyToOne } from "../../../../src"

@Entity()
export class Five {
@PrimaryGeneratedColumn()
id: number

@ManyToOne((type) => One)
one: One

@Column({ type: "text" })
aaaaa: string

@Column({ type: "text" })
bbbbb: string

@Column({ type: "text" })
ccccc: string

@Column({ type: "text" })
ddddd: string

@Column({ type: "text" })
eeeee: string

@Column({ type: "text" })
fffff: string

@Column({ type: "text" })
ggggg: string

@Column({ type: "text" })
hhhhh: string
}
38 changes: 38 additions & 0 deletions test/benchmark/multiple-joins-querybuilder/entity/Four.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Entity } from "../../../../src/decorator/entity/Entity"
import { PrimaryGeneratedColumn } from "../../../../src/decorator/columns/PrimaryGeneratedColumn"
import { Column } from "../../../../src/decorator/columns/Column"
import { One } from "./One"
import { ManyToOne } from "../../../../src"

@Entity()
export class Four {
@PrimaryGeneratedColumn()
id: number

@ManyToOne((type) => One)
one: One

@Column({ type: "text" })
aaaaa: string

@Column({ type: "text" })
bbbbb: string

@Column({ type: "text" })
ccccc: string

@Column({ type: "text" })
ddddd: string

@Column({ type: "text" })
eeeee: string

@Column({ type: "text" })
fffff: string

@Column({ type: "text" })
ggggg: string

@Column({ type: "text" })
hhhhh: string
}
38 changes: 38 additions & 0 deletions test/benchmark/multiple-joins-querybuilder/entity/Nine.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Entity } from "../../../../src/decorator/entity/Entity"
import { PrimaryGeneratedColumn } from "../../../../src/decorator/columns/PrimaryGeneratedColumn"
import { Column } from "../../../../src/decorator/columns/Column"
import { One } from "./One"
import { ManyToOne } from "../../../../src"

@Entity()
export class Nine {
@PrimaryGeneratedColumn()
id: number

@ManyToOne((type) => One)
one: One

@Column({ type: "text" })
aaaaa: string

@Column({ type: "text" })
bbbbb: string

@Column({ type: "text" })
ccccc: string

@Column({ type: "text" })
ddddd: string

@Column({ type: "text" })
eeeee: string

@Column({ type: "text" })
fffff: string

@Column({ type: "text" })
ggggg: string

@Column({ type: "text" })
hhhhh: string
}
73 changes: 73 additions & 0 deletions test/benchmark/multiple-joins-querybuilder/entity/One.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { Entity } from "../../../../src/decorator/entity/Entity"
import { PrimaryGeneratedColumn } from "../../../../src/decorator/columns/PrimaryGeneratedColumn"
import { Column } from "../../../../src/decorator/columns/Column"
import { OneToOne } from "../../../../src"
import { Two } from "./Two"
import { Three } from "./Three"
import { Four } from "./Four"
import { Five } from "./Five"
import { Six } from "./Six"
import { Seven } from "./Seven"
import { Eight } from "./Eight"
import { Nine } from "./Nine"
import { Ten } from "./Ten"

@Entity()
export class One {
@PrimaryGeneratedColumn()
id: number

@OneToOne((type) => Two, (two) => two.one)
two: Two

@OneToOne((type) => Three, (three) => three.one)
three: Three

@OneToOne((type) => Four, (four) => four.one)
four: Four

@OneToOne((type) => Five, (five) => five.one)
five: Five

@OneToOne((type) => Six, (six) => six.one)
six: Six

@OneToOne((type) => Seven, (seven) => seven.one)
seven: Seven

@OneToOne((type) => Eight, (eight) => eight.one)
eight: Eight

@OneToOne((type) => Nine, (nine) => nine.one)
nine: Nine

@OneToOne((type) => Ten, (ten) => ten.one)
ten: Ten

@Column({ type: "text" })
aaaaa: string

@Column({ type: "text" })
bbbbb: string

@Column({ type: "text" })
ccccc: string

@Column({ type: "text" })
ddddd: string

@Column({ type: "text" })
eeeee: string

@Column({ type: "text" })
fffff: string

@Column({ type: "text" })
ggggg: string

@Column({ type: "text" })
hhhhh: string

@Column({ type: "text" })
iiiii: string
}
38 changes: 38 additions & 0 deletions test/benchmark/multiple-joins-querybuilder/entity/Seven.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Entity } from "../../../../src/decorator/entity/Entity"
import { PrimaryGeneratedColumn } from "../../../../src/decorator/columns/PrimaryGeneratedColumn"
import { Column } from "../../../../src/decorator/columns/Column"
import { One } from "./One"
import { ManyToOne } from "../../../../src"

@Entity()
export class Seven {
@PrimaryGeneratedColumn()
id: number

@ManyToOne((type) => One)
one: One

@Column({ type: "text" })
aaaaa: string

@Column({ type: "text" })
bbbbb: string

@Column({ type: "text" })
ccccc: string

@Column({ type: "text" })
ddddd: string

@Column({ type: "text" })
eeeee: string

@Column({ type: "text" })
fffff: string

@Column({ type: "text" })
ggggg: string

@Column({ type: "text" })
hhhhh: string
}
38 changes: 38 additions & 0 deletions test/benchmark/multiple-joins-querybuilder/entity/Six.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Entity } from "../../../../src/decorator/entity/Entity"
import { PrimaryGeneratedColumn } from "../../../../src/decorator/columns/PrimaryGeneratedColumn"
import { Column } from "../../../../src/decorator/columns/Column"
import { One } from "./One"
import { ManyToOne } from "../../../../src"

@Entity()
export class Six {
@PrimaryGeneratedColumn()
id: number

@ManyToOne((type) => One)
one: One

@Column({ type: "text" })
aaaaa: string

@Column({ type: "text" })
bbbbb: string

@Column({ type: "text" })
ccccc: string

@Column({ type: "text" })
ddddd: string

@Column({ type: "text" })
eeeee: string

@Column({ type: "text" })
fffff: string

@Column({ type: "text" })
ggggg: string

@Column({ type: "text" })
hhhhh: string
}
38 changes: 38 additions & 0 deletions test/benchmark/multiple-joins-querybuilder/entity/Ten.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Entity } from "../../../../src/decorator/entity/Entity"
import { PrimaryGeneratedColumn } from "../../../../src/decorator/columns/PrimaryGeneratedColumn"
import { Column } from "../../../../src/decorator/columns/Column"
import { One } from "./One"
import { ManyToOne } from "../../../../src"

@Entity()
export class Ten {
@PrimaryGeneratedColumn()
id: number

@ManyToOne((type) => One)
one: One

@Column({ type: "text" })
aaaaa: string

@Column({ type: "text" })
bbbbb: string

@Column({ type: "text" })
ccccc: string

@Column({ type: "text" })
ddddd: string

@Column({ type: "text" })
eeeee: string

@Column({ type: "text" })
fffff: string

@Column({ type: "text" })
ggggg: string

@Column({ type: "text" })
hhhhh: string
}
38 changes: 38 additions & 0 deletions test/benchmark/multiple-joins-querybuilder/entity/Three.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Entity } from "../../../../src/decorator/entity/Entity"
import { PrimaryGeneratedColumn } from "../../../../src/decorator/columns/PrimaryGeneratedColumn"
import { Column } from "../../../../src/decorator/columns/Column"
import { One } from "./One"
import { ManyToOne } from "../../../../src"

@Entity()
export class Three {
@PrimaryGeneratedColumn()
id: number

@ManyToOne((type) => One)
one: One

@Column({ type: "text" })
aaaaa: string

@Column({ type: "text" })
bbbbb: string

@Column({ type: "text" })
ccccc: string

@Column({ type: "text" })
ddddd: string

@Column({ type: "text" })
eeeee: string

@Column({ type: "text" })
fffff: string

@Column({ type: "text" })
ggggg: string

@Column({ type: "text" })
hhhhh: string
}
Loading

0 comments on commit bda2c2c

Please sign in to comment.