Repository navigation
Lots of optimization. - #52
Conversation
Add support for binary array backend encoding. Move OID type mapping from Connector to ConverterOptions, defaulting to null. Add supporting util functions, some of which are intended for use by future binary backend codecs. Change version on default oid type mapping to somethimg safer. Revert recent changes to EF code in favor of a now defaulted parameter, since EF doesn't know anything about it.
Support arbitrary lower bounds in binary arrays. Evidentally, the null map flag isn't used at all in the frontend/backend binary array representation. Don't use PGUtil.WriteBytes(), because it appends a 0-byte.
Added tests to beat up binary integer array handling. Refactored out some duplicated test code. Properly double-quote and escape array elements in extended query text array formatter.
Add binary backend codecs for text, float and double. Add relevent tests. Demote oid to 32 bits, per its actual size in PG.
Move the UTF8Encoding.GetBytes()/GetString() into the types converters. Optimize some of the type converters, such as ByteArrayToByteaText*(), to avoid the UTF16 encoded Strings; memory used to text encode bytea is now cut in half. Optimize Bind, Parse, Execute, Describe by eliminating calls to UTF8Encoding.GetByteCount(). Queries and text arrays are now built directly to byte[] (MemoryStream), since text parameters are now all returned as UTF8 encoded byte[]. Remove numerous instantiations of UTF8Encoding in favor of one global instantiation. Added an enum of commonly used ASCII characters (as byte) to avoid repeatedly running the encoding on their char counterparts. Added some commonly used ASCII strings (as byte[]).
|
Hi, @glenebob ! What a huge PR :) Excellent! I also think that using byte[] is much better to avoid all the conversion from text. Rungee's work on #51 is also very nice and will be a great contribution. I'll review your PR now and add my comments. |
Optimize NpgsqlCommand.GetParseCommandText(), minus the part that subs parameters (see TODO note).
|
I know I said I wanted to slow down, but, well, I'm obsessed apparently. |
Added PGUtil.WriteLimBytes(). Fluentize the WriteLim*Functions. StartupPacket optimized, fluentized, and reformatted. More fluentization to FastPath.
…nto text_backend_encoding_ascii
|
I have some minor observations about this pr: On NpgsqlBind, you created members to hold the byte values, but kept the string versions. Is this intended? https://github.com/franciscojunior/Npgsql2/pull/52/files#L3R41 I mean, as you already have the byte version of the values, I think there wouldn't need to keep the string version. I think the same happens in the NpgsqlParse class? In NpgsqlCommand.GetParseCommandText, I think it would be better to get another name for the tText variable. Although there is the comment explaining what it is, I think it is a lot confusing. Even more if you consider there is also a parseCommand variable which also can be a possible return value! In the original version there was only the parseCommand variable whose name was self-explainable. About this line: https://github.com/franciscojunior/Npgsql2/pull/52/files#L16R66 in NpgsqlQuery, I think we should still keep it in mind in case of regressions. I remember we received a lot of complains in the past because the user was getting problems caused by the network buffer not being empty before Npgsql started to write on it. I couldn't figure out where the problem was, but we need to check for possible problems when we remove this line. At this line: https://github.com/franciscojunior/Npgsql2/pull/52/files#L29R50, I think the variable name for the minus infinity could be something like: MINUSINFINITY or even MINUS_INFINITY. ? I also think the variable name of https://github.com/franciscojunior/Npgsql2/pull/52/files#L29R45 could be named BYTE_0 and BYTE_1? I think that everything else is ok. Excellent job, @glenebob . I think those changes create a foundation which we can rely on to create other optimizations. :) |
|
On Fri, Sep 20, 2013 at 11:31 AM, Francisco Figueiredo Jr. <
On NpgsqlBind, there are properties to get the values if those strings, so On NpgsqlParse, you're right, the strings can be tossed without effect.
I'm not real happy with the way that function came out, It should now be I started to attack GetPrepareCommandText(), but it got even more Actually, I really want to get the parameter substitution logic down to one About this line:
If it's still a problem, maybe I can figure it out. If not, maybe I can In the mean time, I'll un-comment the Flush().
Excellent! I'll have a commit pushed up shortly :) -Glen |
|
Nice catch about NpgsqlBind. Git diff tricked me :) About NpgsqlCommand.GetParseCommandText, it is really confusing. Please, try getting it at a better shape. It would be very welcome! :) Regarding the Flush() call, I don't remember if there was a bug report about it. Or if it was a forum message. I'll look for it and post a link to here. NEG_INFINITY is ok. I'm looking forward your new commits :) |
Francisco,
Here is where I am currently at with Npgsql. This branch is a fork and continuation of PR 50, so if you merge this, you will get everything in 50 as well. If you merge 50, I will need to marge on my end and send up a new PR for these changes.
This last commit was inspired by Rungee's work on bytea text decoding.
The text backend type codecs now deal with byte[] to and from PG, not string. This allows a potentially huge memory savings in things like bytea, since it can be encoded directly to/from byte[], rather than using strings (which are UTF16) and then UTF8 encoding/decoding. Much much more efficient now. Text array encoding is also now efficient in the same way.
In order to keep that new efficiency, I also had to re-write the query command text generator, writing directly to byte[]. That allows text parameter values to be concatenated without first UTF8 decoding them (and then later UTF8 re-encoding).
The only text encoded data that actually uses anything above the ASCII character range is text itself. In theory, all encodings besides raw text could go directly to/from byte[]. However, I put together an Int2ASCII() function in test (writing directly to byte[]), and no matter how I optimized it, I could not get it much faster than UTF8Encoding.GetBytes(Int32.ToString()), and since the space savings on an individual Int32 is negligible, I left it out.
Some of the optimizations from PR 40 (bind optimizations) are also in here. See my latest comment on that PR.
Note that I did not optimize the bytea text decoders. Rungee did a great job with that. Instead, after this all gets merged, I plan to modify Rungee's optimizations to read directly from the byte[] data from PG, which will make it even more efficient. In the mean time, Rungee's implementation will need to use a UTF8Encoding.GetString() to get the string data it currently needs. Switching it to byte[] will be very simple for me to do.
There's more work to do on this. Bit string I think could be rewritten for use directly on the byte[]. I also noticed a huge opportunity to optimize NpgsqlCommand.GetParseCommandText(). But I kind of want to slow down and get synced back up with your master branch before doing any more work. This PR has gotten really massive.
Welcome back, and happy testing!
-Glen