Skip to content

Commit

Permalink
Speed up JsonConverter again
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Oct 15, 2024
1 parent bbdabac commit 249b7f2
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/JsonConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -454,24 +454,25 @@ public function convert(iterable $records): Iterator
return;
}

$incr = 0;
$chunk = [];
$chunkOffset = 0;
$offset = 0;
$current = $iterator->current();
$iterator->next();

yield $this->start;

while ($iterator->valid()) {
if ($incr === $this->chunkSize) {
if ($chunkOffset === $this->chunkSize) {
yield ($this->jsonEncodeChunk)($chunk).$this->separator;

$incr = 0;
$chunkOffset = 0;
$chunk = [];
}

$chunk[++$offset] = $current;
++$incr;
$chunk[$offset] = $current;
++$chunkOffset;
++$offset;
$current = $iterator->current();
$iterator->next();
}
Expand Down

0 comments on commit 249b7f2

Please sign in to comment.