Skip to content
This repository was archived by the owner on Apr 1, 2024. It is now read-only.

Commit be6650e

Browse files
Swahvayfredemmott
authored andcommitted
Improve batching of Awaitable XHP
If there were nested awaitable XHP elements, then the batching could be split apart by the recursion. This was because `__flushElementChildren()` was being called from within the loop, so childrens’ awaiting would cause the loop to stop. Just set all children and then recursively call `__flushElementChildren()` at the end. fixes #132
1 parent c898d02 commit be6650e

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/core/ComposableElement.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -449,13 +449,9 @@ final protected function __transferContext(
449449
}
450450

451451
$childWaitHandles = Map{};
452-
$flushWaitHandles = Vector{};
453452
do {
454-
if ($childWaitHandles || $flushWaitHandles) {
455-
list($awaitedChildren, $_) = await GenArrayWaitHandle::create(array(
456-
GenMapWaitHandle::create($childWaitHandles),
457-
GenVectorWaitHandle::create($flushWaitHandles),
458-
));
453+
if ($childWaitHandles) {
454+
$awaitedChildren = await GenMapWaitHandle::create($childWaitHandles);
459455
if ($awaitedChildren) {
460456
foreach ($awaitedChildren as $i => $awaitedChild) {
461457
$this->children->set($i, $awaitedChild);
@@ -464,7 +460,6 @@ final protected function __transferContext(
464460
$this->replaceChildren(<x:frag>{$this->children}</x:frag>);
465461
$childWaitHandles = Map{};
466462
}
467-
$flushWaitHandles = Vector{};
468463
}
469464

470465
$ln = count($this->children);
@@ -492,10 +487,6 @@ final protected function __transferContext(
492487
$this->children->removeKey($i);
493488
$i--;
494489
} else {
495-
if ($child instanceof :x:primitive) {
496-
$flushWaitHandles[] =
497-
$child->__flushElementChildren()->getWaitHandle();
498-
}
499490
assert($child instanceof XHPChild);
500491
$this->children[$i] = $child;
501492
}
@@ -504,6 +495,13 @@ final protected function __transferContext(
504495
}
505496
} while ($childWaitHandles);
506497

498+
$flushWaitHandles = Vector{};
499+
foreach ($this->children as $child) {
500+
if ($child instanceof :x:primitive) {
501+
$flushWaitHandles[] = $child->__flushElementChildren()->getWaitHandle();
502+
}
503+
}
504+
507505
if ($flushWaitHandles) {
508506
await GenVectorWaitHandle::create($flushWaitHandles);
509507
}
@@ -655,7 +653,7 @@ final private function validateChildrenExpression(
655653
case XHPChildrenExpressionType::SINGLE:
656654
// Exactly once -- :fb-thing
657655
return $this->validateChildrenRule($expr, $index);
658-
case XHPChildrenExpressionType::ANY_NUMBER:
656+
case XHPChildrenExpressionType::ANY_NUMBER:
659657
// Zero or more times -- :fb-thing*
660658
do {
661659
list($ret, $index) = $this->validateChildrenRule(

0 commit comments

Comments
 (0)