#At file:///H:/connector_net/6.0/ based on revid:vvaintroub@stripped
828 Vladislav Vaintroub 2010-07-28
Bug #48243 : improve write performance of compressed stream.
Reduce number of network writes in CompressAndSendCache()
from eight (a single write operation for each byte in packet
length prefix plus single write for data itself) to one (send packet
length prefix and data in a single buffer).
This fixes was a regression from 5.2 (in 5.2, buffered output
was used, and writing bytes individually was not a problem)
modified:
CHANGES
MySql.Data/Provider/Source/CompressedStream.cs
=== modified file 'CHANGES'
--- a/CHANGES 2010-07-27 21:53:37 +0000
+++ b/CHANGES 2010-07-28 14:05:00 +0000
@@ -1,4 +1,6 @@
-- Improve performance of MySqlHelper.EscapeString() (Bug#48243)
+- Improve performance of write operations (e.g insert) if compression is enabled
+ (Bug #48243)
+- Improve performance of MySqlHelper.EscapeString()
- Fix membership provider creation failure, when default database character set is different from latin1 (Bug #53174)
- Fix "Connection must be valid and open" exception When UpdateBatchSize > 1
and MySqlDataAdapter is not using an open connection (Bug #38411)
=== modified file 'MySql.Data/Provider/Source/CompressedStream.cs'
--- a/MySql.Data/Provider/Source/CompressedStream.cs 2009-07-29 11:06:15 +0000
+++ b/MySql.Data/Provider/Source/CompressedStream.cs 2010-07-28 14:05:00 +0000
@@ -209,35 +209,40 @@ namespace MySql.Data.MySqlClient
// now we set our compressed and uncompressed lengths
// based on if our compression is going to help or not
+ MemoryStream memStream;
+
if (compressedBuffer == null)
{
compressedLength = cache.Length;
uncompressedLength = 0;
+ memStream = cache;
}
else
{
compressedLength = compressedBuffer.Length;
uncompressedLength = cache.Length;
+ memStream = compressedBuffer;
}
- baseStream.WriteByte((byte) (compressedLength & 0xff));
- baseStream.WriteByte((byte) ((compressedLength >> 8) & 0xff));
- baseStream.WriteByte((byte) ((compressedLength >> 16) & 0Xff));
- baseStream.WriteByte(seq);
- baseStream.WriteByte((byte) (uncompressedLength & 0xff));
- baseStream.WriteByte((byte) ((uncompressedLength >> 8) & 0xff));
- baseStream.WriteByte((byte) ((uncompressedLength >> 16) & 0Xff));
-
- if (compressedBuffer == null)
- baseStream.Write(cacheBuffer, 0, (int) cache.Length);
- else
- {
- byte[] compressedBytes = compressedBuffer.GetBuffer();
- baseStream.Write(compressedBytes, 0, (int) compressedBuffer.Length);
- }
+ // Make space for length prefix (7 bytes) at the start of output
+ long dataLength = memStream.Length;
+ int bytesToWrite = (int)dataLength + 7;
+ memStream.SetLength(bytesToWrite);
+
+ byte[] buffer = memStream.GetBuffer();
+ Array.Copy(buffer, 0, buffer, 7, dataLength);
+
+ // Write length prefix
+ buffer[0] = (byte) (compressedLength & 0xff);
+ buffer[1] = (byte) ((compressedLength >> 8) & 0xff);
+ buffer[2] = (byte) ((compressedLength >> 16) & 0xff);
+ buffer[3] = seq;
+ buffer[4] = (byte) (uncompressedLength & 0xff);
+ buffer[5] = (byte) ((uncompressedLength >> 8) & 0xff);
+ buffer[6] = (byte) ((uncompressedLength >> 16) & 0xff);
+ baseStream.Write(buffer, 0, bytesToWrite);
baseStream.Flush();
-
cache.SetLength(0);
}
Attachment: [text/bzr-bundle] bzr/vvaintroub@mysql.com-20100728140500-z5xczzy81xco2b0i.bundle
Thread |
---|
• bzr commit into connector-net-6.0 branch (vvaintroub:828) Bug#48243 | Vladislav Vaintroub | 28 Jul |