Skip to content

feat(client): improve perfomance of generating path for client#2046

Open
sterligov wants to merge 2 commits into
oapi-codegen:mainfrom
sterligov:feat-gen-client-path-string
Open

feat(client): improve perfomance of generating path for client#2046
sterligov wants to merge 2 commits into
oapi-codegen:mainfrom
sterligov:feat-gen-client-path-string

Conversation

@sterligov
Copy link
Copy Markdown

In this pull request, I made a small performance improvement to the client by using string concatenation instead of fmt.Sprintf. Below, I’ll include the benchmark results.

goos: darwin
goarch: arm64
pkg: github.com/oapi-codegen/oapi-codegen/v2/pkg/codegen
cpu: Apple M1 Pro
BenchmarkFmtPath1param
BenchmarkFmtPath1param-10       	21433833	        49.99 ns/op	      16 B/op	       1 allocs/op
BenchmarkConcatPath1param
BenchmarkConcatPath1param-10    	73644105	        16.27 ns/op	       0 B/op	       0 allocs/op
BenchmarkFmtPath2param
BenchmarkFmtPath2param-10       	18985250	        62.78 ns/op	      16 B/op	       1 allocs/op
BenchmarkConcatPath2param
BenchmarkConcatPath2param-10    	55796110	        21.45 ns/op	       0 B/op	       0 allocs/op
BenchmarkFmtPath3param
BenchmarkFmtPath3param-10       	15205623	        79.05 ns/op	      24 B/op	       1 allocs/op
BenchmarkConcatPath3param
BenchmarkConcatPath3param-10    	41759646	        28.44 ns/op	       0 B/op	       0 allocs/op
PASS

@sterligov sterligov requested a review from a team as a code owner August 2, 2025 05:06
@kusari-inspector
Copy link
Copy Markdown

kusari-inspector Bot commented Aug 2, 2025

Kusari Analysis Results

Analysis for commit: b690045, performed at: 2025-08-02T11:55:19Z

@kusari-inspector rerun - Trigger a re-analysis of this PR

@kusari-inspector feedback [your message] - Send feedback to our AI and team


Recommendation

✅ PROCEED with this Pull Request

Summary

No Flagged Issues Detected

All values appear to be within acceptable risk parameters.

No pinned version dependency changes, code issues or exposed secrets detected!

Found this helpful? Give it a 👍 or 👎 reaction!

@sterligov sterligov force-pushed the feat-gen-client-path-string branch from 501b237 to ea62ed3 Compare August 2, 2025 05:09
@kusari-inspector
Copy link
Copy Markdown

Kusari PR Analysis rerun based on - ea62ed3 performed at: 2025-08-02T05:09:15Z - link to updated analysis

@sterligov sterligov force-pushed the feat-gen-client-path-string branch from ea62ed3 to fab1963 Compare August 2, 2025 05:11
@kusari-inspector
Copy link
Copy Markdown

Kusari PR Analysis rerun based on - fab1963 performed at: 2025-08-02T05:11:59Z - link to updated analysis

@sterligov sterligov force-pushed the feat-gen-client-path-string branch from fab1963 to a3cd398 Compare August 2, 2025 06:16
@kusari-inspector
Copy link
Copy Markdown

Kusari PR Analysis rerun based on - a3cd398 performed at: 2025-08-02T06:16:38Z - link to updated analysis

@sterligov sterligov force-pushed the feat-gen-client-path-string branch from a3cd398 to 1511442 Compare August 2, 2025 07:22
@kusari-inspector
Copy link
Copy Markdown

Kusari PR Analysis rerun based on - 1511442 performed at: 2025-08-02T07:22:05Z - link to updated analysis

@jamietanna
Copy link
Copy Markdown
Member

Thanks, will try and review at some point. Is it worth committing the benchmark code for future testing?

@kusari-inspector
Copy link
Copy Markdown

Kusari PR Analysis rerun based on - 3acf76d performed at: 2025-08-02T11:53:02Z - link to updated analysis

@sterligov
Copy link
Copy Markdown
Author

Thanks, will try and review at some point. Is it worth committing the benchmark code for future testing?

I added a commit with a benchmark test

@sterligov sterligov force-pushed the feat-gen-client-path-string branch from 3acf76d to b690045 Compare August 2, 2025 11:55
@kusari-inspector
Copy link
Copy Markdown

Kusari PR Analysis rerun based on - b690045 performed at: 2025-08-02T11:55:19Z - link to updated analysis

@jamietanna
Copy link
Copy Markdown
Member

Thanks. From what I can see:

Before:

% cd ./pkg/codegen
% go test ./ -bench=.
goos: linux
goarch: amd64
pkg: github.com/oapi-codegen/oapi-codegen/v2/pkg/codegen
cpu: 12th Gen Intel(R) Core(TM) i7-12800H
Benchmark_concatPath1param-20           131724429               10.39 ns/op            0 B/op          0 allocs/op
Benchmark_concatPath2param-20           25299087                44.80 ns/op           48 B/op          1 allocs/op
PASS
ok      github.com/oapi-codegen/oapi-codegen/v2/pkg/codegen     3.672s
go test ./ -bench=.  5.07s user 0.64s system 141% cpu 4.032 total

After:

% cd ./pkg/codegen
% go test ./ -bench=.
goos: linux
goarch: amd64
pkg: github.com/oapi-codegen/oapi-codegen/v2/pkg/codegen
cpu: 12th Gen Intel(R) Core(TM) i7-12800H
Benchmark_concatPath1param-20           130095781                8.806 ns/op           0 B/op          0 allocs/op
Benchmark_concatPath2param-20           34524310                37.85 ns/op           48 B/op          1 allocs/op
PASS
ok      github.com/oapi-codegen/oapi-codegen/v2/pkg/codegen     3.674s
go test ./ -bench=.  4.89s user 0.53s system 135% cpu 3.994 total

Is that right? The performance improvement seems fairly low

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.

2 participants