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

add operator batch() #170

Merged
merged 1 commit into from
Aug 18, 2021
Merged

add operator batch() #170

merged 1 commit into from
Aug 18, 2021

Conversation

staltz
Copy link
Member

@staltz staltz commented Aug 17, 2021

For issue #167

Achieved in a non-breaking manner, paginate() remains as it is, causing the final pull-stream to emit arrays of messages. We introduce batch() that has the same performance profile as paginate(), but just configure how the results should be streamed: one message at a time, no array of messages.

@staltz staltz requested a review from arj03 August 17, 2021 13:32
@@ -396,9 +400,9 @@ function toPullStream() {
function paginateStream(ops) {
let seq = meta.seq || 0
let total = Infinity
const limit = meta.pageSize || 1
const limit = meta.pageSize || meta.batchSize || 20
Copy link
Member Author

Choose a reason for hiding this comment

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

The default 1 was actually pretty bad for performance. Reminder: #123 (comment)

@github-actions
Copy link

Benchmark results

Part Speed Heap Change Samples
Count 1 big index (3rd run) 0.35ms ± 0.04ms 21.49 kB ± 19.55 kB 43
Create an index twice concurrently 769.21ms ± 16.59ms -71.5 kB ± 103.82 kB 72
Load core indexes 0.83ms ± 0.02ms 86.65 B ± 178.9 B 9040
Load two indexes concurrently 1813.27ms ± 19.97ms -158.9 kB ± 187.52 kB 11
Paginate 10 results 21.62ms ± 1.34ms -7.88 kB ± 28.78 kB 24
Paginate 20000 msgs with pageSize=5 6358.79ms ± 90.85ms 521.34 kB ± 5581.84 kB 5
Paginate 20000 msgs with pageSize=500 598.43ms ± 21.46ms -95.45 kB ± 145.67 kB 18
Query 1 big index (1st run) 1143.39ms ± 10.81ms -52.12 kB ± 63.36 kB 47
Query 1 big index (2nd run) 294.67ms ± 4.37ms 72.64 kB ± 69.15 kB 43
Query 3 indexes (1st run) 1512.63ms ± 9.72ms 73.15 kB ± 136.36 kB 35
Query 3 indexes (2nd run) 207.59ms ± 2.22ms -2.59 kB ± 286.44 kB 54
Query a prefix map (1st run) 253.57ms ± 3.28ms 17.78 kB ± 522.38 kB 23
Query a prefix map (2nd run) 11.87ms ± 0.8ms -5.35 kB ± 12.76 kB 22

Copy link
Member

@arj03 arj03 left a comment

Choose a reason for hiding this comment

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

Thanks, this looks good and is a quite small change in the number of lines.

Very happy we are integrating these best patterns into the library. Feels like next level in a way from fixing bugs :)

@staltz staltz merged commit bc56b12 into master Aug 18, 2021
@staltz staltz deleted the paginate-better branch August 18, 2021 07:17
@github-actions
Copy link

Benchmark results

Part Speed Heap Change Samples
Count 1 big index (3rd run) 0.37ms ± 0.06ms 9 kB ± 25.29 kB 49
Create an index twice concurrently 1005.88ms ± 25.54ms -71.5 kB ± 102.2 kB 54
Load core indexes 0.71ms ± 0.01ms 88.56 B ± 173.87 B 9988
Load two indexes concurrently 1198.38ms ± 262.46ms 74.05 kB ± 346.05 kB 14
Paginate 10 results 19.96ms ± 1.32ms 11.31 kB ± 47.11 kB 25
Paginate 20000 msgs with pageSize=5 5789.71ms ± 196.64ms 807.38 kB ± 3672.47 kB 5
Paginate 20000 msgs with pageSize=500 751.32ms ± 35.54ms 16.19 kB ± 864.01 kB 15
Query 1 big index (1st run) 1311.87ms ± 15.41ms -23.25 kB ± 84.55 kB 41
Query 1 big index (2nd run) 296.25ms ± 3.1ms 70.32 kB ± 74.27 kB 43
Query 3 indexes (1st run) 1571.66ms ± 6.91ms 104.87 kB ± 122.04 kB 34
Query 3 indexes (2nd run) 203.35ms ± 2.86ms 30.59 kB ± 240.54 kB 55
Query a prefix map (1st run) 241.86ms ± 1.75ms -32.9 kB ± 468.4 kB 24
Query a prefix map (2nd run) 11.71ms ± 0.71ms 5.68 kB ± 27.28 kB 22

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.

2 participants