Skip to content

[SQLite] Bump and use byte[] variants added to blob_open for performance#25047

Merged
jasonmalinowski merged 6 commits intodotnet:masterfrom
Therzok:sqlite-blob
May 29, 2018
Merged

[SQLite] Bump and use byte[] variants added to blob_open for performance#25047
jasonmalinowski merged 6 commits intodotnet:masterfrom
Therzok:sqlite-blob

Conversation

@Therzok
Copy link
Copy Markdown
Contributor

@Therzok Therzok commented Feb 25, 2018

Fixes #23424

NOTE: Currently using CI as a build bot, roslyn builds take too much time on my machine.

Ask Mode template not completed

Customer scenario

What does the customer do to get into this situation, and why do we think this
is common enough to address for this release. (Granted, sometimes this will be
obvious "Open project, VS crashes" but in general, I need to understand how
common a scenario is)

Bugs this fixes

(either VSO or GitHub links)

Workarounds, if any

Also, why we think they are insufficient for RC vs. RC2, RC3, or RTW

Risk

This is generally a measure our how central the affected code is to adjacent
scenarios and thus how likely your fix is to destabilize a broader area of code

Performance impact

(with a brief justification for that assessment (e.g. "Low perf impact because no extra allocations/no complexity changes" vs. "Low")

Is this a regression from a previous update?

Root cause analysis

How did we miss it? What tests are we adding to guard against it in the future?

How was the bug found?

(E.g. customer reported it vs. ad hoc testing)

Test documentation updated?

If this is a new non-compiler feature or a significant improvement to an existing feature, update https://github.com/dotnet/roslyn/wiki/Manual-Testing once you know which release it is targeting.

@Therzok Therzok requested review from a team as code owners February 25, 2018 21:45
@Therzok
Copy link
Copy Markdown
Contributor Author

Therzok commented Feb 25, 2018

I went with the route of adding another property (<Name>Ptr) simply due to the fact that string versions may also be used in other places.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is Util.ToUtf8 and Util.to_utf8?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No space before (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this overload need to exist? who is calling into ReadBlob with a string for the table name or column name?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it was public API, so not sure if it's safe to completely remove it (although the class is internal).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can remove this overload if we don't need it (it's currently not used anywhere)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Please remove the overload. This type is completely internal to roslyn. We do not have to worry about breaking changes here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't the ColumnName be a byte[] too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, good catches so far. I haven't compiled locally, so this probably has issues even at compile time :p

@Therzok Therzok force-pushed the sqlite-blob branch 3 times, most recently from 8812e66 to fdf4f0c Compare February 25, 2018 22:06
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CyrusNajmabadi had forgotten to commit this file.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be documented why you're doing this (i presume sqlite requires 0 terminated utf8?).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was shamelessly copy pasted from sqlitepcl.raw :p

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be clear. By 'documented', i meant: 'comment in the code' :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I did add some comments.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs copyright.

Copy link
Copy Markdown
Contributor

@sharwell sharwell Feb 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 This method could be reduced to the following if you want it simple. You may end up with a couple extra NUL characters in the converted string, but it would be usable.

return Encoding.UTF8.GetBytes(text + '\0');

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Encoding.UTF8.GetBytes(string) internally calls the byte[] variant, https://github.com/dotnet/corefx/blob/master/src/Common/src/CoreLib/System/Text/Encoding.cs#L770-L781

So, that would incur:
1 string allocation '\0' -> "0"
1 string allocation for the string concat (text + "0")

I used this method for performance.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used this method for performance.

Relative impact of costs needs to be considered. So, for example, your change helps replace an unending amount of string->byte[] allocations with a single fixed number of allocations (<10). Improving allocation scenarios doesn't mean removing all allocations, just the costly ones :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that said, i'm fine with the code as is. It's nice and clear and doesn't do anything that seems unnecessary. Seems like a good solution to me.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I just realized that I changed this locally before I moved the things to happen in the static ctors. I can simplify the code.

@Therzok Therzok force-pushed the sqlite-blob branch 2 times, most recently from a7bf633 to 5f95e8a Compare February 26, 2018 07:46
Copy link
Copy Markdown
Member

@jasonmalinowski jasonmalinowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some nitpicks around naming and stuff. Would like them fixed, but otherwise good.

My standard "are you sure you want to target master?" applies.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be called "ToUtf8WithNullTerminator" or something. Seeing initial use my thought was "why do we need a helper?"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readonly? Yeah, the array is still mutable but it's a small protection.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readonly everything here.

@jasonmalinowski
Copy link
Copy Markdown
Member

Also, @sharwell or @jinujoe this will probably require a bump in the open source tool to track the new dependency. Who wants to own following up on that?

@heejaechang
Copy link
Copy Markdown
Contributor

nice.

@Therzok
Copy link
Copy Markdown
Contributor Author

Therzok commented Feb 27, 2018

Should be ok now.

@Therzok
Copy link
Copy Markdown
Contributor Author

Therzok commented Feb 27, 2018

I think 15-7 is what we want.

@Therzok Therzok changed the base branch from master to dev15.7.x February 27, 2018 09:00
@Therzok
Copy link
Copy Markdown
Contributor Author

Therzok commented Mar 1, 2018

Fixed the Windows VisualStudio projects. Build should go green soon.

Opened another issue about other projects not using the Packages.props values. #25148

@Therzok
Copy link
Copy Markdown
Contributor Author

Therzok commented Mar 1, 2018

@jasonmalinowski any idea what I might be doing wrong with the nuget package version?

@jasonmalinowski
Copy link
Copy Markdown
Member

jasonmalinowski commented Mar 1, 2018

It looks like the package changed from having assets under the win7-x86 RID it's now just win-x86. You'll have to fix those paths. If you crack the nuget package you can see what's inside.

@Therzok
Copy link
Copy Markdown
Contributor Author

Therzok commented May 22, 2018

Failures look unrelated?

@heejaechang
Copy link
Copy Markdown
Contributor

@jasonmalinowski
Copy link
Copy Markdown
Member

Yes, the queues are currently under maintinence. Given we don't have great unit test coverage of this, I'm tempted to say let's wait until those come back up before merging this.

Have we also done the OSS paperwork? That needs to be done before merging.

@Therzok
Copy link
Copy Markdown
Contributor Author

Therzok commented May 22, 2018

On another note, I should probably upgrade to a newer sqlitepclraw, as 1.1.11 is out.

@heejaechang
Copy link
Copy Markdown
Contributor

heejaechang commented May 22, 2018

@jinujoseph no idea on when we are supposed to move the version up. and what paper work we need to do.

@jinujoseph
Copy link
Copy Markdown
Contributor

new version bump will need paper work and understanding of why we would want to move .

@jasonmalinowski
Copy link
Copy Markdown
Member

And I should comment: the paperwork is sometimes just rubber-stamped by a tool, so it's possibly quite easy.

@Therzok
Copy link
Copy Markdown
Contributor Author

Therzok commented May 23, 2018

Fwiw, I saw submissions for 1.1.11 in osstool

@jasonmalinowski
Copy link
Copy Markdown
Member

@Therzok Cool, then it might get rubber stamped. @jinujoseph who is doing the paperwork then, at least to see if it gets the rubber stamp?

@jinujoseph
Copy link
Copy Markdown
Contributor

@ivanbasov is helping with the paperwork here..thanks

@ivanbasov
Copy link
Copy Markdown
Contributor

I've sent a request for the OSS permission approval for sqlite. I will keep you informed.

@ivanbasov
Copy link
Copy Markdown
Contributor

All the paperwork has been approved. We can proceed with the merge. Thank you!

@jasonmalinowski
Copy link
Copy Markdown
Member

@jinujoseph This just needs an delegated M2 approval then.

@jinujoseph
Copy link
Copy Markdown
Contributor

Approved to merge for 15.8.Preview3

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.

Allocations caused by SQLitePCL.raw database loading

9 participants