Skip to content

Commit f71f9e3

Browse files
committed
Improve trace parcing performance
About 19% faster for a large Laravel project with a 16GB trace
1 parent a825f14 commit f71f9e3

File tree

7 files changed

+206
-178
lines changed

7 files changed

+206
-178
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"php": "^7.4|^8.0",
1515
"ext-xdebug": "*",
1616
"composer/xdebug-handler": "^3.0",
17-
"symfony/console": "^5.4"
17+
"symfony/console": "^5.4",
18+
"symfony/polyfill-php80": "^1.27"
1819
},
1920
"require-dev": {
2021
"mockery/mockery": "^1.6",

composer.lock

Lines changed: 165 additions & 165 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/PHPWeaver/Command/WeaveCommand.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9292
foreach ($paths as $path) {
9393
if (!is_string($path))
9494
return self::RETURN_CODE_ERROR;
95+
$path = realpath($path);
96+
if (!$path)
97+
return self::RETURN_CODE_ERROR;
9598
$pathsToWeave[] = $path;
9699
}
97100
$tracefile = $input->getOption('tracefile');
@@ -103,7 +106,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
103106

104107
$filesToWeave = $this->getFilesToProcess($pathsToWeave);
105108

106-
$sigs = $this->parseTrace($tracefile);
109+
$sigs = $this->parseTrace($tracefile, $pathsToWeave);
107110
$this->transformFiles($filesToWeave, $sigs);
108111

109112
return self::RETURN_CODE_OK;
@@ -146,13 +149,15 @@ private function getFilesToProcess(array $pathsToWeave): array
146149

147150
/**
148151
* Parse the trace file.
152+
*
153+
* @param string[] $pathsToWeave
149154
*/
150-
private function parseTrace(string $tracefile): Signatures
155+
private function parseTrace(string $tracefile, array $pathsToWeave): Signatures
151156
{
152157
$sigs = new Signatures();
153158
if (is_file($tracefile)) {
154159
$traceFile = new SplFileObject($tracefile);
155-
$trace = new TraceReader(new FunctionTracer(new TraceSignatureLogger($sigs)));
160+
$trace = new TraceReader(new FunctionTracer(new TraceSignatureLogger($sigs)), $pathsToWeave);
156161

157162
$traceFile->setFlags(SplFileObject::READ_AHEAD);
158163
$this->progressBarStart(iterator_count($traceFile), '<info>Parsing tracefile …</info>');

0 commit comments

Comments
 (0)