Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 006dacd

Browse filesBrowse files
committed
minor #29762 Improved performance of LoggerDataCollector (javiereguiluz)
This PR was squashed before being merged into the 4.3-dev branch (closes #29762). Discussion ---------- Improved performance of LoggerDataCollector | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no <!-- don't forget to update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | - <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | - My feeling is that Symfony's "dev" environment is more and more slow lately. After profiling the Symfony Demo app with Blackfire, I found that `getContainerCompilerLogs()` is one of the slowest methods. Given that you rarely need or look at these "compiler logs", in this PR I propose to get them only when/if you really need them. [The before/after profile comparison](https://blackfire.io/profiles/compare/4959d918-8e00-4cd7-9b0b-41919e73ae62/graph) confirms a nice performance improvement and thousands of functions no longer called. Commits ------- 3b8d6d1 Improved performance of LoggerDataCollector
2 parents 0083ba1 + 3b8d6d1 commit 006dacd
Copy full SHA for 006dacd

File tree

1 file changed

+7
-5
lines changed
Filter options

1 file changed

+7
-5
lines changed

‎src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php
+7-5Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ public function lateCollect()
6666
if (null !== $this->logger) {
6767
$containerDeprecationLogs = $this->getContainerDeprecationLogs();
6868
$this->data = $this->computeErrorsCount($containerDeprecationLogs);
69-
$this->data['compiler_logs'] = $this->getContainerCompilerLogs();
69+
// get compiler logs later (only when they are needed) to improve performance
70+
$this->data['compiler_logs'] = array();
71+
$this->data['compiler_logs_filepath'] = $this->containerPathPrefix.'Compiler.log';
7072
$this->data['logs'] = $this->sanitizeLogs(array_merge($this->logger->getLogs($this->currentRequest), $containerDeprecationLogs));
7173
$this->data = $this->cloneVar($this->data);
7274
}
@@ -110,7 +112,7 @@ public function countScreams()
110112

111113
public function getCompilerLogs()
112114
{
113-
return isset($this->data['compiler_logs']) ? $this->data['compiler_logs'] : array();
115+
return $this->cloneVar($this->getContainerCompilerLogs($this->data['compiler_logs_filepath'] ?? null));
114116
}
115117

116118
/**
@@ -143,14 +145,14 @@ private function getContainerDeprecationLogs()
143145
return $logs;
144146
}
145147

146-
private function getContainerCompilerLogs()
148+
private function getContainerCompilerLogs(?string $compilerLogsFilepath = null): array
147149
{
148-
if (null === $this->containerPathPrefix || !file_exists($file = $this->containerPathPrefix.'Compiler.log')) {
150+
if (!file_exists($compilerLogsFilepath)) {
149151
return array();
150152
}
151153

152154
$logs = array();
153-
foreach (file($file, FILE_IGNORE_NEW_LINES) as $log) {
155+
foreach (file($compilerLogsFilepath, FILE_IGNORE_NEW_LINES) as $log) {
154156
$log = explode(': ', $log, 2);
155157
if (!isset($log[1]) || !preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+(?:\\\\[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+)++$/', $log[0])) {
156158
$log = array('Unknown Compiler Pass', implode(': ', $log));

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.