Skip to content

optimization: compare: avoid initializing config when it's not needed - #563

Merged
zeroshade merged 1 commit into
apache:mainfrom
pixelherodev:typeequal-optimize
Nov 7, 2025
Merged

optimization: compare: avoid initializing config when it's not needed#563
zeroshade merged 1 commit into
apache:mainfrom
pixelherodev:typeequal-optimize

Conversation

@pixelherodev

Copy link
Copy Markdown
Contributor

This makes Schema.Equal ~20% faster in my use case (where the hot path is almost always taken, left == right).

cfg escapes to the heap; this change avoids making cfg exist until after the hot path, making it even faster.

Rationale for this change

What changes are included in this PR?

Are these changes tested?

Are there any user-facing changes?

This makes Schema.Equal ~25% faster in my use case
@pixelherodev

Copy link
Copy Markdown
Contributor Author

Before:

BenchmarkIPC/Writer/codec=plain-24         	 201799	     5907 ns/op	   8160 B/op	     91 allocs/op
BenchmarkIPC/Reader/codec=plain-24         	 245958	     5379 ns/op	   5995 B/op	     76 allocs/op
BenchmarkIPC/Writer/codec=zstd-24          	   3900	   312365 ns/op	2338754 B/op	    150 allocs/op
BenchmarkIPC/Reader/codec=zstd-24          	  43340	    26273 ns/op	  25739 B/op	    187 allocs/op
BenchmarkIPC/Writer/codec=lz4-24           	 107146	    11394 ns/op	  12859 B/op	    134 allocs/op
BenchmarkIPC/Reader/codec=lz4-24           	 122874	     9815 ns/op	   9948 B/op	    117 allocs/op

After:

BenchmarkIPC/Writer/codec=plain-24         	 182833	     6042 ns/op	   8152 B/op	     90 allocs/op
BenchmarkIPC/Reader/codec=plain-24         	 253102	     5157 ns/op	   5986 B/op	     74 allocs/op
BenchmarkIPC/Writer/codec=zstd-24          	   3471	   334912 ns/op	2338755 B/op	    149 allocs/op
BenchmarkIPC/Reader/codec=zstd-24          	  44372	    26691 ns/op	  25734 B/op	    185 allocs/op
BenchmarkIPC/Writer/codec=lz4-24           	 104529	    11472 ns/op	  12766 B/op	    133 allocs/op
BenchmarkIPC/Reader/codec=lz4-24           	 113907	     9676 ns/op	   9931 B/op	    115 allocs/op
@zeroshade
zeroshade merged commit d3f3b98 into apache:main Nov 7, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants