Skip to content

Use generators to generate RPC payload data - #1044

Merged
arthurschreiber merged 2 commits into
tediousjs:masterfrom
IanChokS:refactor-buffer
Feb 9, 2020
Merged

arthurschreiber merged 2 commits into
tediousjs:masterfrom
IanChokS:refactor-buffer

Conversation

@IanChokS

Copy link
Copy Markdown
Member

No description provided.

Comment thread src/connection.ts Resolved
Comment thread src/rpcrequest-payload.ts Resolved
Comment thread src/rpcrequest-payload.ts Resolved
Comment thread src/rpcrequest-payload.ts Resolved
@codecov

codecov Bot commented Jan 30, 2020 •

Copy link
Copy Markdown

Codecov Report

Merging #1044 into master will decrease coverage by 5.83%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1044      +/-   ##
==========================================
- Coverage   80.29%   74.45%   -5.84%     
==========================================
  Files          86       86              
  Lines        4405     4397       -8     
  Branches      778      777       -1     
==========================================
- Hits         3537     3274     -263     
- Misses        614      852     +238     
- Partials      254      271      +17
Impacted Files Coverage Δ
src/rpcrequest-payload.ts 82.97% <100%> (-9.75%) ⬇️
src/token/nbcrow-token-parser.ts 3.57% <0%> (-71.43%) ⬇️
src/transaction.ts 20% <0%> (-65%) ⬇️
src/data-types/time.ts 51.21% <0%> (-46.35%) ⬇️
src/sqlbatch-payload.ts 60% <0%> (-33.34%) ⬇️
src/metadata-parser.ts 60.34% <0%> (-32.76%) ⬇️
src/token/colmetadata-token-parser.ts 55.26% <0%> (-31.58%) ⬇️
src/data-types/datetime2.ts 57.14% <0%> (-28.58%) ⬇️
src/value-parser.ts 64.58% <0%> (-17.71%) ⬇️
src/token/token.ts 70.94% <0%> (-17.1%) ⬇️
... and 14 more

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 4584999...a5be21d. Read the comment docs.

@arthurschreiber arthurschreiber changed the title Refactor buffer Use generators to generate RPC payload data Feb 9, 2020
@arthurschreiber

Copy link
Copy Markdown
Collaborator

Before

$ node benchmarks/query/insert-varbinary.js 
query/insert-varbinary.js size=10 n=10: 308.6890408599335
query/insert-varbinary.js size=1024 n=10: 311.47775919536076
query/insert-varbinary.js size=1048576 n=10: 18.102475918534246
query/insert-varbinary.js size=10485760 n=10: 2.109837591831322
query/insert-varbinary.js size=10 n=100: 497.5944393940821
query/insert-varbinary.js size=1024 n=100: 401.36903928896766
query/insert-varbinary.js size=1048576 n=100: 18.25438779354878
query/insert-varbinary.js size=10485760 n=100: 2.250578908715709

$ node benchmarks/query/select-varbinary.js 
query/select-varbinary.js size=10 n=10: 347.8905223315275
query/select-varbinary.js size=100 n=10: 343.6256665693634
query/select-varbinary.js size=1000 n=10: 355.023165971626
query/select-varbinary.js size=10000 n=10: 328.7983708435283
query/select-varbinary.js size=1048576 n=10: 28.922057533567365
query/select-varbinary.js size=10485760 n=10: 3.61266827520264
query/select-varbinary.js size=10 n=100: 524.0513003670094
query/select-varbinary.js size=100 n=100: 545.4001204723419
query/select-varbinary.js size=1000 n=100: 482.9299872299306
query/select-varbinary.js size=10000 n=100: 405.018117776717
query/select-varbinary.js size=1048576 n=100: 32.81065020423878
query/select-varbinary.js size=10485760 n=100: 3.524019660813264

$ node benchmarks/request/rpcrequest-payload.js 
request/rpcrequest-payload.js size=1048576 n=10: 321.78192015509376
request/rpcrequest-payload.js size=10485760 n=10: 49.40733090363232
request/rpcrequest-payload.js size=52428800 n=10: 8.52002443536192
request/rpcrequest-payload.js size=1048576 n=100: 597.4325503430123
request/rpcrequest-payload.js size=10485760 n=100: 62.95259916749355
request/rpcrequest-payload.js size=52428800 n=100: 11.697934463285144

After

$ node benchmarks/query/insert-varbinary.js 
query/insert-varbinary.js size=10 n=10: 279.0921311592354
query/insert-varbinary.js size=1024 n=10: 312.6991209371042
query/insert-varbinary.js size=1048576 n=10: 20.249761407692457
query/insert-varbinary.js size=10485760 n=10: 2.1134659008144805
query/insert-varbinary.js size=10 n=100: 445.1387124563054
query/insert-varbinary.js size=1024 n=100: 435.0690013780289
query/insert-varbinary.js size=1048576 n=100: 22.43368865230221
query/insert-varbinary.js size=10485760 n=100: 2.366485339029834

$ node benchmarks/query/select-varbinary.js 
query/select-varbinary.js size=10 n=10: 338.18833119716675
query/select-varbinary.js size=100 n=10: 325.718979045586
query/select-varbinary.js size=1000 n=10: 333.5310950372841
query/select-varbinary.js size=10000 n=10: 320.3208743888598
query/select-varbinary.js size=1048576 n=10: 27.974499900564638
query/select-varbinary.js size=10485760 n=10: 3.343897240855387
query/select-varbinary.js size=10 n=100: 486.66409941620947
query/select-varbinary.js size=100 n=100: 541.0536085167336
query/select-varbinary.js size=1000 n=100: 501.0910380444101
query/select-varbinary.js size=10000 n=100: 415.54201777837517
query/select-varbinary.js size=1048576 n=100: 29.55069400842108
query/select-varbinary.js size=10485760 n=100: 3.5741086078328834

$ node benchmarks/request/rpcrequest-payload.js 
request/rpcrequest-payload.js size=1048576 n=10: 445.0352534676034
request/rpcrequest-payload.js size=10485760 n=10: 80.31625456905117
request/rpcrequest-payload.js size=52428800 n=10: 16.873847022688324
request/rpcrequest-payload.js size=1048576 n=100: 876.175028473717
request/rpcrequest-payload.js size=10485760 n=100: 106.22369527530356
request/rpcrequest-payload.js size=52428800 n=100: 21.44433932107644

Analysis

Not much of a change here, performance wise. We're a bit slower for small payloads, because we're allocating more smaller buffers now in generateData and generateParameterData (at least one buffer per parameter, plus some other buffers that hold other request data). Before, a single WritableTrackingBuffer was used with an initial size that could hold parameter data for requests with small payloads without any additional allocations.

For larger parameter data, we're a bit faster because less parameters no longer share the same buffer which needed to be re-sized often.

I expect that this will improve (both for small requests as well as larger requests) with the other changes we're planning to do next. 👍

@arthurschreiber

Copy link
Copy Markdown
Collaborator

🎉 This PR is included in version 8.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants