Skip to content

Commit

Permalink
Improve trace parcing performance
Browse files Browse the repository at this point in the history
About 19% faster for a large Laravel project with a 16GB trace
  • Loading branch information
AJenbo committed Jul 28, 2023
1 parent a825f14 commit f71f9e3
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 178 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"php": "^7.4|^8.0",
"ext-xdebug": "*",
"composer/xdebug-handler": "^3.0",
"symfony/console": "^5.4"
"symfony/console": "^5.4",
"symfony/polyfill-php80": "^1.27"
},
"require-dev": {
"mockery/mockery": "^1.6",
Expand Down
330 changes: 165 additions & 165 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions src/PHPWeaver/Command/WeaveCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
foreach ($paths as $path) {
if (!is_string($path))
return self::RETURN_CODE_ERROR;
$path = realpath($path);
if (!$path)
return self::RETURN_CODE_ERROR;
$pathsToWeave[] = $path;
}
$tracefile = $input->getOption('tracefile');
Expand All @@ -103,7 +106,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

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

$sigs = $this->parseTrace($tracefile);
$sigs = $this->parseTrace($tracefile, $pathsToWeave);
$this->transformFiles($filesToWeave, $sigs);

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

/**
* Parse the trace file.
*
* @param string[] $pathsToWeave
*/
private function parseTrace(string $tracefile): Signatures
private function parseTrace(string $tracefile, array $pathsToWeave): Signatures
{
$sigs = new Signatures();
if (is_file($tracefile)) {
$traceFile = new SplFileObject($tracefile);
$trace = new TraceReader(new FunctionTracer(new TraceSignatureLogger($sigs)));
$trace = new TraceReader(new FunctionTracer(new TraceSignatureLogger($sigs)), $pathsToWeave);

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

0 comments on commit f71f9e3

Please sign in to comment.