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

Optimise struct field layout #7052

Merged
merged 1 commit into from Nov 19, 2020

Conversation

systay
Copy link
Collaborator

@systay systay commented Nov 18, 2020

Using the tool https://github.com/orijtech/structslop, I got this recommendation.

~/dev/vitess/go/mysql/binlog_event.go:130:19: struct has size 56 (size class 64), could be 48 (size class 48), you'll save 25.00% if you rearrange it to:
struct {
	HeaderSizes       []byte
	ServerVersion     string
	FormatVersion     uint16
	HeaderLength      byte
	ChecksumAlgorithm byte
}

~/dev/vitess/go/mysql/conn.go:81:11: struct has size 240 (size class 240), could be 224 (size class 224), you'll save 6.67% if you rearrange it to:
struct {
	fields                 []*query.Field
	schemaName             string
	ClientData             interface{}
	conn                   net.Conn
	flavor                 flavor
	ServerVersion          string
	User                   string
	UserData               Getter
	bufferedReader         *bufio.Reader
	flushTimer             *time.Timer
	currentEphemeralPolicy int
	currentEphemeralBuffer *[]byte
	listener               *Listener
	bufferedWriter         *bufio.Writer
	PrepareData            map[uint32]*PrepareData
	bufMu                  sync.Mutex
	Capabilities           uint32
	closed                 sync2.AtomicBool
	ConnectionID           uint32
	StatementID            uint32
	StatusFlags            uint16
	CharacterSet           uint8
	sequence               uint8
}

~/dev/vitess/go/mysql/conn.go:187:18: struct has size 88 (size class 96), could be 80 (size class 80), you'll save 16.67% if you rearrange it to:
struct {
	ParamsType  []int32
	ColumnNames []string
	PrepareStmt string
	BindVars    map[string]*query.BindVariable
	StatementID uint32
	ParamsCount uint16
}

~/dev/vitess/go/mysql/server.go:122:15: struct has size 136 (size class 144), could be 128 (size class 128), you'll save 11.11% if you rearrange it to:
struct {
	authServer               AuthServer
	handler                  Handler
	listener                 net.Listener
	ServerVersion            string
	TLSConfig                atomic.Value
	SlowConnectWarnThreshold sync2.AtomicDuration
	connReadBufferSize       int
	connWriteTimeout         time.Duration
	connReadTimeout          time.Duration
	connectionID             uint32
	AllowClearTextWithoutTLS sync2.AtomicBool
	shutdown                 sync2.AtomicBool
	RequireSecureTransport   bool
}

Using https://github.com/orijtech/structslop, these changes should make some of our fields more memory efficient.

Signed-off-by: Andres Taylor <andres@planetscale.com>
@systay systay changed the title Optimized struct field layout Optimise struct field layout Nov 18, 2020
@harshit-gangal harshit-gangal merged commit 92e60ab into vitessio:master Nov 19, 2020
@systay systay deleted the struct-field-optimize branch November 19, 2020 11:30
@askdba askdba added this to the v9.0 milestone Nov 27, 2020
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.

None yet

3 participants