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

Performance | Improve performance of SQLServerDataTable.internalAddRow() function #990

Merged
merged 15 commits into from
May 22, 2019

Conversation

cheenamalhotra
Copy link
Member

Fixes issue #531 and #539

Rework of PR #538

@codecov-io
Copy link

codecov-io commented Mar 14, 2019

Codecov Report

Merging #990 into dev will decrease coverage by <.01%.
The diff coverage is 80.7%.

Impacted file tree graph

@@             Coverage Diff              @@
##                dev     #990      +/-   ##
============================================
- Coverage     53.01%   53.01%   -0.01%     
- Complexity     3158     3161       +3     
============================================
  Files           119      119              
  Lines         28022    28023       +1     
  Branches       4688     4680       -8     
============================================
  Hits          14857    14857              
- Misses        10928    10942      +14     
+ Partials       2237     2224      -13
Impacted Files Coverage Δ Complexity Δ
...m/microsoft/sqlserver/jdbc/SQLServerDataTable.java 81.75% <80.7%> (+11%) 42 <0> (+6) ⬆️
...om/microsoft/sqlserver/jdbc/ReaderInputStream.java 43.95% <0%> (-3.3%) 15% <0%> (-1%)
...in/java/com/microsoft/sqlserver/jdbc/IOBuffer.java 60.87% <0%> (-0.37%) 0% <0%> (ø)
...m/microsoft/sqlserver/jdbc/SQLServerResultSet.java 43.87% <0%> (-0.31%) 324% <0%> (-3%)
...rc/main/java/com/microsoft/sqlserver/jdbc/dtv.java 68.78% <0%> (+0.11%) 0% <0%> (ø) ⬇️
...n/java/com/microsoft/sqlserver/jdbc/Parameter.java 67.61% <0%> (+0.2%) 64% <0%> (ø) ⬇️
...ncurrentlinkedhashmap/ConcurrentLinkedHashMap.java 39.22% <0%> (+0.43%) 44% <0%> (+1%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b91c7ea...7595479. Read the comment docs.

@cheenamalhotra
Copy link
Member Author

@alexnixon @cogman

I recreated the original PR #538 for improving performance in SQLServerDataTable considering regression scenarios and what we discussed before. I have added tests to cover discussed cases.

Note: I relooked over allowing custom object types when adding row data, and I think that should be supported as it is. The underlying datatype being passed decides the type of the value added to the column and should work as expected.

Let me know if you have any concerns.

@alexnixon
Copy link

alexnixon commented Mar 20, 2019

Hi @cheenamalhotra.

Thanks for revisiting this. Initial thoughts are that having some tests around this is great.

On performance though this PR still leaves lots of cases which go via string serialization. For example using a java.lang.Integer to set a BIGINT field or using a java.lang.Byte to set a BIT field.

The type-testing approach I suggested in this comment on the previous PR handles all these cases and more - do you have an objection to it?

(defaulting to using toString for unknown types as you suggested seems fair enough for backwards compatibility's sake)

@cheenamalhotra
Copy link
Member Author

Hi @alexnixon

I considered that before but it increases code complexity and performs conversions even when not needed (which impacts performance for corresponding types).

With this change, we do give maximum performance for corresponding datatypes, but for values whose datatypes do not correspond to JDBC Type, we support them by converting to String generically... which seems a fair deal to me. It is not something that we recommend for users either way and need not overload implementation for all such possibilities.

@alexnixon
Copy link

Could you give me specific example of an unneeded conversion? I'm struggling to see any case in which my suggestion is slower[1] but can see many important cases which are substantially faster (e.g. the aforementioned using an java.lang.Integer to set a BIGINT field).

I know performance isn't often a big deal but these cases are abysmally slow and given the client is using TVPs it's not unlikely they're shoveling large amount of data through here.

[1] unless you count the (BIGINT, Long) case, where I didn't write the Long type-test first, so technically there are a few instructions being wasted. Easy to shuffle that test to the top if you care.

@cogman
Copy link
Contributor

cogman commented Mar 22, 2019

@alexnixon I believe @cheenamalhotra is referring to all the instance of checks that end up happening.

I believe the complexity tradeoff is fair. In most (all?) cases I'm matching the types up anyways. Even if I didn't do that, I could make the decision to do it at the point of creating the TVP to get better performance with @cheenamalhotra's implementation (I could handle the up/down casting myself)

cogman
cogman previously approved these changes Mar 23, 2019
Copy link
Contributor

@cogman cogman left a comment

Choose a reason for hiding this comment

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

I don't know what sort of approve authority I have, even if the small changes I suggested aren't implemented I think things look fine.

@cheenamalhotra
Copy link
Member Author

@alexnixon There are many computations going on in that approach, and I think its fair to keep the implementation less complicated inside driver. e.g. working with all Numeric types as Long and then converting them to Short/Integer class objects, etc. also opens up endless possibilities with other types too, whereas it doesn't give much of an advantage vs its need for end user.

And as far as performance is concerned, I agree the corresponding types must be quickly passed through and hence this change is well deserved.

@cogman Thanks, I made quick modifications as per your suggestions. It looks clean now.

@cheenamalhotra cheenamalhotra added this to the 7.3.1 milestone Mar 28, 2019
peterbae
peterbae previously approved these changes Apr 8, 2019
lilgreenbird
lilgreenbird previously approved these changes Apr 11, 2019
@cheenamalhotra cheenamalhotra dismissed stale reviews from rene-ye and peterbae via e0cc2e6 May 14, 2019 22:51
ulvii
ulvii previously approved these changes May 15, 2019
rene-ye
rene-ye previously approved these changes May 16, 2019
peterbae
peterbae previously approved these changes May 16, 2019
# Conflicts:
#	src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataTable.java
@cheenamalhotra cheenamalhotra dismissed stale reviews from peterbae, rene-ye, and ulvii via 0e8bb83 May 19, 2019 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants