-
Notifications
You must be signed in to change notification settings - Fork 2.3k
optimize readPacket #1705
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
optimize readPacket #1705
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,19 +25,30 @@ import ( | |
// https://dev.mysql.com/doc/dev/mysql-server/latest/PAGE_PROTOCOL.html | ||
// https://mariadb.com/kb/en/clientserver-protocol/ | ||
|
||
// read n bytes from mc.buf | ||
func (mc *mysqlConn) readNext(n int) ([]byte, error) { | ||
if mc.buf.len() < n { | ||
err := mc.buf.fill(n, mc.readWithTimeout) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Go compiler inlines mc.buff.fill. It doesn't allocate mc.readWithTimeout. It may be possible to rewrite in cleaner code. But I minimise changes to backport this PR to 1.9 branch. |
||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
return mc.buf.readNext(n), nil | ||
} | ||
|
||
// Read packet to buffer 'data' | ||
func (mc *mysqlConn) readPacket() ([]byte, error) { | ||
var prevData []byte | ||
invalidSequence := false | ||
|
||
readNext := mc.buf.readNext | ||
readNext := mc.readNext | ||
if mc.compress { | ||
readNext = mc.compIO.readNext | ||
} | ||
|
||
for { | ||
// read packet header | ||
data, err := readNext(4, mc.readWithTimeout) | ||
data, err := readNext(4) | ||
Comment on lines
-40
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. go compiler allocated |
||
if err != nil { | ||
mc.close() | ||
if cerr := mc.canceled.Value(); cerr != nil { | ||
|
@@ -85,7 +96,7 @@ func (mc *mysqlConn) readPacket() ([]byte, error) { | |
} | ||
|
||
// read packet body [pktLen bytes] | ||
data, err = readNext(pktLen, mc.readWithTimeout) | ||
data, err = readNext(pktLen) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto. |
||
if err != nil { | ||
mc.close() | ||
if cerr := mc.canceled.Value(); cerr != nil { | ||
|