Skip to content

Conversation

ThomasRooney
Copy link
Member

@ThomasRooney ThomasRooney commented Jul 7, 2025

Context:

Strict Mode effectively produced a warning when there was an overlay action that didn't do anything.
It was done by serialising the document before and after each change and doing a comparison. Super inefficient.
This makes it work by returning back a "didChange" boolean all the way from applyNode depending on the kind of change that happened.

From:

cpu: Apple M3 Max
BenchmarkApplyToStrictBySize
BenchmarkApplyToStrictBySize/2KB
apply_test.go:206: OpenAPI size: 16911 bytes (target: 2048, paths added: 0)
BenchmarkApplyToStrictBySize/2KB-14 738 1600568 ns/op
BenchmarkApplyToStrictBySize/20KB
apply_test.go:206: OpenAPI size: 22741 bytes (target: 20480, paths added: 16)
BenchmarkApplyToStrictBySize/20KB-14 493 2377933 ns/op
BenchmarkApplyToStrictBySize/200KB
apply_test.go:206: OpenAPI size: 245551 bytes (target: 204800, paths added: 625)
BenchmarkApplyToStrictBySize/200KB-14 48 23456246 ns/op
BenchmarkApplyToStrictBySize/2M
apply_test.go:206: OpenAPI size: 2477637 bytes (target: 2048000, paths added: 6708)
BenchmarkApplyToStrictBySize/2M-14 5 235112558 ns/op
PASS
To:

BenchmarkApplyToStrictBySize
BenchmarkApplyToStrictBySize/2KB
apply_test.go:206: OpenAPI size: 16911 bytes (target: 2048, paths added: 0)
BenchmarkApplyToStrictBySize/2KB-14 200113 6067 ns/op
BenchmarkApplyToStrictBySize/20KB
apply_test.go:206: OpenAPI size: 22741 bytes (target: 20480, paths added: 16)
BenchmarkApplyToStrictBySize/20KB-14 192753 6248 ns/op
BenchmarkApplyToStrictBySize/200KB
apply_test.go:206: OpenAPI size: 245551 bytes (target: 204800, paths added: 625)
BenchmarkApplyToStrictBySize/200KB-14 170931 7046 ns/op
BenchmarkApplyToStrictBySize/2M
apply_test.go:206: OpenAPI size: 2477637 bytes (target: 2048000, paths added: 6708)
BenchmarkApplyToStrictBySize/2M-14 216870 5873 ns/op
PASS

Size Before (ns/op) After (ns/op) Speedup
2KB 1,600,568 6,067 263.8x
20KB 2,377,933 6,248 380.6x
200KB 23,456,246 7,046 3329.1x
2MB 235,112,558 5,873 40032.8x

@ThomasRooney ThomasRooney force-pushed the perf/apply-to-strict branch from a0c2f84 to 63ac80d Compare July 7, 2025 10:30
@ThomasRooney ThomasRooney merged commit efed836 into main Jul 7, 2025
4 checks passed
module github.com/speakeasy-api/openapi-overlay

go 1.22
go 1.24
Copy link
Contributor

Choose a reason for hiding this comment

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

Did we need to bump this (and in a patch version)?

Coming from oapi-codegen/oapi-codegen#2017 and we try and keep a go directive compatability where possible, so this was a surprise to see in a patch release

(it's a great patch to improve performance 👏🏽)

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.

3 participants