-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #391: Optimize garbage collecting
- Loading branch information
Showing
106 changed files
with
513 additions
and
392 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of Temporal package. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Temporal\Internal\Declaration; | ||
|
||
/** | ||
* Means that instance can be destroyed. It's preferred to destroy instance to guarantee | ||
* that all resources related to it will be released. | ||
*/ | ||
interface Destroyable | ||
{ | ||
public function destroy(): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of Temporal package. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Temporal\Internal\Support; | ||
|
||
/** | ||
* Garbage collector that might be called after some number of ticks or after certain timeout. | ||
* @internal | ||
*/ | ||
final class GarbageCollector | ||
{ | ||
/** @var positive-int Last time when GC was called. */ | ||
private int $lastTime; | ||
|
||
/** @var int<0, max> Number of ticks since last GC. */ | ||
private int $counter = 0; | ||
|
||
/** | ||
* @param positive-int $threshold Number of ticks before GC will be called. | ||
* @param int<0, max> $timeout Timeout in seconds. | ||
* @param positive-int|null $lastTime Start point for timeout. | ||
*/ | ||
public function __construct( | ||
private readonly int $threshold, | ||
private readonly int $timeout, | ||
?int $lastTime = null, | ||
) { | ||
$this->lastTime = $lastTime ?? \time(); | ||
} | ||
|
||
/** | ||
* Check if GC should be called. | ||
*/ | ||
public function check(): bool | ||
{ | ||
if (++$this->counter >= $this->threshold) { | ||
return true; | ||
} | ||
|
||
if (\time() - $this->lastTime > $this->timeout) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* Call GC. | ||
*/ | ||
public function collect(): void | ||
{ | ||
\gc_collect_cycles(); | ||
|
||
$this->lastTime = \time(); | ||
$this->counter = 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.