diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-03-14 00:32:30 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-03-14 00:32:30 +0900 |
| commit | 9bf23e2abf74d70b77726a4300917c78bc8035e7 (patch) | |
| tree | a4d4695b334e1cdb9864787766598f2900600e49 | |
| parent | f490780439450a06cf71eb40b453fc0154264337 (diff) | |
| download | php-waddiwasi-9bf23e2abf74d70b77726a4300917c78bc8035e7.tar.gz php-waddiwasi-9bf23e2abf74d70b77726a4300917c78bc8035e7.tar.zst php-waddiwasi-9bf23e2abf74d70b77726a4300917c78bc8035e7.zip | |
perf: cache current frame
| -rw-r--r-- | benchmarks/20240314-0030.log | 4 | ||||
| -rw-r--r-- | src/Execution/Stack.php | 17 | ||||
| -rw-r--r-- | traces/20240314-0030.stderr.log | 8 |
3 files changed, 27 insertions, 2 deletions
diff --git a/benchmarks/20240314-0030.log b/benchmarks/20240314-0030.log new file mode 100644 index 0000000..9ab0496 --- /dev/null +++ b/benchmarks/20240314-0030.log @@ -0,0 +1,4 @@ +Benchmark 1: make run + Time (mean ± σ): 4.500 s ± 0.060 s [User: 4.418 s, System: 0.082 s] + Range (min … max): 4.427 s … 4.598 s 10 runs + diff --git a/src/Execution/Stack.php b/src/Execution/Stack.php index 396cb29..a96a875 100644 --- a/src/Execution/Stack.php +++ b/src/Execution/Stack.php @@ -13,6 +13,8 @@ final class Stack */ private array $frames = []; + private ?Frame $currentFrame = null; + /** * @param list<int|float|Ref|Frame|Label> $entries */ @@ -25,6 +27,7 @@ final class Stack { $this->push($frame); $this->frames[] = $frame; + $this->currentFrame = $frame; } public function pushLabel(Label $label): void @@ -62,6 +65,11 @@ final class Stack $result = $this->pop(); assert($result instanceof Frame); array_pop($this->frames); + if (count($this->frames) === 0) { + $this->currentFrame = null; + } else { + $this->currentFrame = end($this->frames); + } return $result; } @@ -137,6 +145,11 @@ final class Stack } } array_pop($this->frames); + if (count($this->frames) === 0) { + $this->currentFrame = null; + } else { + $this->currentFrame = end($this->frames); + } } public function top(): int|float|Ref|Frame|Label|null @@ -157,8 +170,8 @@ final class Stack public function currentFrame(): Frame { - assert(count($this->frames) !== 0); - return $this->frames[count($this->frames) - 1]; + assert($this->currentFrame !== null); + return $this->currentFrame; } private function push(int|float|Ref|Frame|Label $entry): void diff --git a/traces/20240314-0030.stderr.log b/traces/20240314-0030.stderr.log new file mode 100644 index 0000000..dae98f4 --- /dev/null +++ b/traces/20240314-0030.stderr.log @@ -0,0 +1,8 @@ +Decoding... +Instantiating... +Executing... + +Exit code: 0 +Memory peak usage: 195983240 + + |
