Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fewer wire allocs in SQL() implementations #2788

Merged
merged 10 commits into from
Dec 10, 2024
Merged

Conversation

max-hoffman
Copy link
Contributor

@max-hoffman max-hoffman commented Dec 10, 2024

Optimizes SQL() implementations that convert interface values into type-specific byte arrays. Combination of skipping runtime.convT checks, that unnecessarily allocated variables to the heap, redundant byte array copying, and other conversion inefficiencies.

dolt perf here: dolthub/dolt#8651

goos: darwin
goarch: arm64
pkg: github.com/dolthub/go-mysql-server/sql/types
cpu: Apple M3 Pro
                │  before.txt  │             after.txt              │
                │    sec/op    │   sec/op     vs base               │
NumI64SQL-12       62.04n ± 2%   51.13n ± 1%  -17.59% (p=0.002 n=6)
Varchar10SQL-12    66.85n ± 1%   31.38n ± 2%  -53.06% (p=0.002 n=6)
TimespanSQL-12     62.36n ± 0%   40.31n ± 1%  -35.35% (p=0.002 n=6)
TimestampSQL-12   1960.0n ± 1%   255.0n ± 2%  -86.99% (p=0.002 n=6)
DatetimeSQL-12    1968.5n ± 0%   269.5n ± 3%  -86.31% (p=0.002 n=6)
EnumSQL-12        111.85n ± 1%   37.49n ± 1%  -66.48% (p=0.002 n=6)
SetSQL-12         175.15n ± 0%   63.55n ± 1%  -63.72% (p=0.002 n=6)
BitSQL-12          41.84n ± 1%   41.74n ± 1%        ~ (p=0.589 n=6)
DecimalSQL-12      683.8n ± 3%   281.9n ± 1%  -58.77% (p=0.002 n=6)
NumF64SQL-12      105.15n ± 1%   91.72n ± 0%  -12.77% (p=0.002 n=6)
geomean            189.2n        80.50n       -57.45%

                │  before.txt  │              after.txt              │
                │     B/op     │    B/op     vs base                 │
NumI64SQL-12        24.00 ± 0%   16.00 ± 0%  -33.33% (p=0.002 n=6)
Varchar10SQL-12    40.000 ± 0%   8.000 ± 0%  -80.00% (p=0.002 n=6)
TimespanSQL-12      24.00 ± 0%   16.00 ± 0%  -33.33% (p=0.002 n=6)
TimestampSQL-12   1520.00 ± 0%   56.00 ± 0%  -96.32% (p=0.002 n=6)
DatetimeSQL-12    1520.00 ± 0%   56.00 ± 0%  -96.32% (p=0.002 n=6)
EnumSQL-12        112.000 ± 0%   8.000 ± 0%  -92.86% (p=0.002 n=6)
SetSQL-12          136.00 ± 0%   16.00 ± 0%  -88.24% (p=0.002 n=6)
BitSQL-12           16.00 ± 0%   16.00 ± 0%        ~ (p=1.000 n=6) ¹
DecimalSQL-12       439.0 ± 0%   228.0 ± 0%  -48.06% (p=0.002 n=6)
NumF64SQL-12        38.00 ± 0%   31.00 ± 0%  -18.42% (p=0.002 n=6)
geomean             108.0        24.94       -76.92%
¹ all samples are equal

                │ before.txt  │              after.txt              │
                │  allocs/op  │ allocs/op   vs base                 │
NumI64SQL-12       2.000 ± 0%   1.000 ± 0%  -50.00% (p=0.002 n=6)
Varchar10SQL-12    2.000 ± 0%   1.000 ± 0%  -50.00% (p=0.002 n=6)
TimespanSQL-12     2.000 ± 0%   1.000 ± 0%  -50.00% (p=0.002 n=6)
TimestampSQL-12   42.000 ± 0%   3.000 ± 0%  -92.86% (p=0.002 n=6)
DatetimeSQL-12    42.000 ± 0%   3.000 ± 0%  -92.86% (p=0.002 n=6)
EnumSQL-12         3.000 ± 0%   1.000 ± 0%  -66.67% (p=0.002 n=6)
SetSQL-12          5.000 ± 0%   2.000 ± 0%  -60.00% (p=0.002 n=6)
BitSQL-12          2.000 ± 0%   2.000 ± 0%        ~ (p=1.000 n=6) ¹
DecimalSQL-12      22.00 ± 0%   10.00 ± 0%  -54.55% (p=0.002 n=6)
NumF64SQL-12       3.000 ± 0%   2.000 ± 0%  -33.33% (p=0.002 n=6)
geomean            5.554        1.931       -65.24%
¹ all samples are equal

Copy link
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

@max-hoffman max-hoffman merged commit 9643b85 into main Dec 10, 2024
7 of 8 checks passed
@max-hoffman max-hoffman deleted the max/fewer-wire-allocs branch December 10, 2024 23:47
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