Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

[dc-rules] add rule for sql structs #25

Open
peakle opened this issue Jan 31, 2022 · 0 comments
Open

[dc-rules] add rule for sql structs #25

peakle opened this issue Jan 31, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@peakle
Copy link
Member

peakle commented Jan 31, 2022

Is your feature request related to a problem? Please describe.
add rule which will check sql structs with pointers to basic types (string, int, bool, etc) and will recommend change it to sql.Null* type. So we can decrease load on heap and increase runtime speed

POC:

type RowHeap struct {
	Str *string `db:"str"`
}

type RowStack struct {
	Str sql.NullString `db:"str"`
}

BenchmarkResults https://github.com/peakle/meetup/blob/master/go-optimizations/bench2_test.go:

RowHeap:
BenchmarkRowHeap-16           59960768                19.82 ns/op           16 B/op          1 allocs/op
BenchmarkRowHeap-16           61210947                21.10 ns/op           16 B/op          1 allocs/op
BenchmarkRowHeap-16           49640668                28.02 ns/op           16 B/op          1 allocs/op

RowStack:
BenchmarkRowStack-16           1000000000               0.7385 ns/op          0 B/op          0 allocs/op
BenchmarkRowStack-16           1000000000               0.7114 ns/op          0 B/op          0 allocs/op
BenchmarkRowStack-16           1000000000               0.7178 ns/op          0 B/op          0 allocs/op
@peakle peakle added the enhancement New feature or request label Feb 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant