Skip to content

Commit 358240c

Browse files
author
Piotr Jastrzebski
committed
Push up to 128 frames in sync
In my tests, this speeds up push 4-5 times. Making push of 300 frames take 4-5s instead of 20s. Signed-off-by: Piotr Jastrzebski <[email protected]>
1 parent 263fbad commit 358240c

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

libsql/src/sync.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -538,19 +538,28 @@ async fn try_push(
538538

539539
let mut frame_no = start_frame_no;
540540
while frame_no <= end_frame_no {
541-
let frame = conn.wal_get_frame(frame_no, page_size)?;
541+
let batch_size = 128.min(end_frame_no - frame_no + 1);
542+
let mut frames = conn.wal_get_frame(frame_no, page_size)?;
543+
if batch_size > 1 {
544+
frames.reserve((batch_size - 1) as usize * frames.len());
545+
}
546+
for idx in 1..batch_size {
547+
let frame = conn.wal_get_frame(frame_no + idx, page_size)?;
548+
frames.extend_from_slice(frame.as_ref())
549+
}
542550

543551
// The server returns its maximum frame number. To avoid resending
544552
// frames the server already knows about, we need to update the
545553
// frame number to the one returned by the server.
546554
let max_frame_no = sync_ctx
547-
.push_frames(frame.freeze(), generation, frame_no, 1)
555+
.push_frames(frames.freeze(), generation, frame_no, batch_size)
548556
.await?;
549557

550558
if max_frame_no > frame_no {
551-
frame_no = max_frame_no;
559+
frame_no = max_frame_no + 1;
560+
} else {
561+
frame_no += batch_size;
552562
}
553-
frame_no += 1;
554563
}
555564

556565
sync_ctx.write_metadata().await?;

0 commit comments

Comments
 (0)