Skip to content

optimize ForeignKey.HashOf()#10554

Merged
jycor merged 9 commits intomainfrom
james/fks
Feb 26, 2026
Merged

optimize ForeignKey.HashOf()#10554
jycor merged 9 commits intomainfrom
james/fks

Conversation

@jycor
Copy link
Copy Markdown
Contributor

@jycor jycor commented Feb 24, 2026

This PR optimizes the ForeignKey.HashOf() function to be about 55% faster by using a sync.Pool of []byte instead of bytes.Buffer.

Unfortunately, this only accounts for like 0.2% of total tppc cpu runtime.

Old:

BenchmarkForeignKeyHashOf-14    	 2012511	       578.7 ns/op

New:

BenchmarkForeignKeyHashOf-14    	 4511584	       260.0 ns/op

@coffeegoddd
Copy link
Copy Markdown
Contributor

@jycor DOLT

comparing_percentages
100.000000 to 100.000000
version result total
e55f75f ok 5937471
version total_tests
e55f75f 5937471
correctness_percentage
100.0

@coffeegoddd
Copy link
Copy Markdown
Contributor

@jycor DOLT

comparing_percentages
100.000000 to 100.000000
version result total
aed3439 ok 5937471
version total_tests
aed3439 5937471
correctness_percentage
100.0

@coffeegoddd
Copy link
Copy Markdown
Contributor

@jycor DOLT

comparing_percentages
100.000000 to 100.000000
version result total
691bd70 ok 5937471
version total_tests
691bd70 5937471
correctness_percentage
100.0

@coffeegoddd
Copy link
Copy Markdown
Contributor

@jycor DOLT

comparing_percentages
100.000000 to 100.000000
version result total
b14dfed ok 5937471
version total_tests
b14dfed 5937471
correctness_percentage
100.0

@coffeegoddd
Copy link
Copy Markdown
Contributor

@jycor DOLT

comparing_percentages
100.000000 to 100.000000
version result total
7b8b0ef ok 5937471
version total_tests
7b8b0ef 5937471
correctness_percentage
100.0

@jycor
Copy link
Copy Markdown
Contributor Author

jycor commented Feb 25, 2026

#benchmark

@github-actions
Copy link
Copy Markdown

@jycor jycor changed the title hardcode foreign key collection HashOf() optimize ForeignKey.HashOf() Feb 25, 2026
@coffeegoddd
Copy link
Copy Markdown
Contributor

@jycor DOLT

comparing_percentages
100.000000 to 100.000000
version result total
9c4bcac ok 5937471
version total_tests
9c4bcac 5937471
correctness_percentage
100.0

@coffeegoddd
Copy link
Copy Markdown
Contributor

@jycor DOLT

comparing_percentages
100.000000 to 100.000000
version result total
c0932c5 ok 5937471
version total_tests
c0932c5 5937471
correctness_percentage
100.0

Copy link
Copy Markdown
Contributor

@angelamayxie angelamayxie left a comment

Choose a reason for hiding this comment

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

Is there a way to avoid using append?

@jycor
Copy link
Copy Markdown
Contributor Author

jycor commented Feb 26, 2026

It's probably possible to rewrite this without using append(), but I don't think it would be any different performance-wise?
If my understanding is correct, append() should only cause reallocations when the new entry exceeds capacity.

Copy link
Copy Markdown
Member

@zachmu zachmu left a comment

Choose a reason for hiding this comment

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

LGTM

@coffeegoddd
Copy link
Copy Markdown
Contributor

@jycor DOLT

comparing_percentages
100.000000 to 100.000000
version result total
e5a6ba7 ok 5937471
version total_tests
e5a6ba7 5937471
correctness_percentage
100.0

@coffeegoddd
Copy link
Copy Markdown
Contributor

@jycor DOLT

test_name from_latency_p95 to_latency_p95 percent_change
tpcc-scale-factor-1 61.08 61.08 0.0
test_name from_server_name from_server_version from_tps to_server_name to_server_version to_tps percent_change
tpcc-scale-factor-1 dolt 448f95c 37.85 dolt e5a6ba7 38.03 0.48

@jycor jycor merged commit 332c6a3 into main Feb 26, 2026
25 checks passed
@jycor jycor deleted the james/fks branch February 27, 2026 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants