mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-19 05:12:41 +01:00
Improve Diffusion browse performance for large files
Summary: When looking at a large file in Diffusion: - disable highlighting if it's huge and show a note about why; - pick up a few other optimizations. Test Plan: Locally, this improves the main render of `__phutil_library_map__.php` from 3,200ms to 600ms for me, at the cost of syntax highlighting (we can eventually add view options and let users re-enable it). Reviewers: chad Reviewed By: chad Differential Revision: https://secure.phabricator.com/D14959
This commit is contained in:
parent
9728c65e93
commit
91a01e5703
2 changed files with 54 additions and 31 deletions
|
@ -585,6 +585,8 @@ final class DiffusionBrowseController extends DiffusionController {
|
||||||
}
|
}
|
||||||
|
|
||||||
$file_corpus = $file_content->getCorpus();
|
$file_corpus = $file_content->getCorpus();
|
||||||
|
$highlight_limit = DifferentialChangesetParser::HIGHLIGHT_BYTE_LIMIT;
|
||||||
|
$can_highlight = (strlen($file_corpus) <= $highlight_limit);
|
||||||
|
|
||||||
if (!$show_color) {
|
if (!$show_color) {
|
||||||
$lines = phutil_split_lines($file_corpus);
|
$lines = phutil_split_lines($file_corpus);
|
||||||
|
@ -625,12 +627,16 @@ final class DiffusionBrowseController extends DiffusionController {
|
||||||
implode('', $rows));
|
implode('', $rows));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
require_celerity_resource('syntax-highlighting-css');
|
if ($can_highlight) {
|
||||||
|
require_celerity_resource('syntax-highlighting-css');
|
||||||
|
|
||||||
$highlighted = PhabricatorSyntaxHighlighter::highlightWithFilename(
|
$highlighted = PhabricatorSyntaxHighlighter::highlightWithFilename(
|
||||||
$path,
|
$path,
|
||||||
$file_corpus);
|
$file_corpus);
|
||||||
$lines = phutil_split_lines($highlighted);
|
$lines = phutil_split_lines($highlighted);
|
||||||
|
} else {
|
||||||
|
$lines = phutil_split_lines($file_corpus);
|
||||||
|
}
|
||||||
|
|
||||||
$rows = $this->buildDisplayRows(
|
$rows = $this->buildDisplayRows(
|
||||||
$lines,
|
$lines,
|
||||||
|
@ -706,6 +712,18 @@ final class DiffusionBrowseController extends DiffusionController {
|
||||||
->appendChild($corpus)
|
->appendChild($corpus)
|
||||||
->setCollapsed(true);
|
->setCollapsed(true);
|
||||||
|
|
||||||
|
if (!$can_highlight) {
|
||||||
|
$message = pht(
|
||||||
|
'This file is larger than %s, so syntax highlighting is disabled '.
|
||||||
|
'by default.',
|
||||||
|
phutil_format_bytes($highlight_limit));
|
||||||
|
|
||||||
|
$corpus->setInfoView(
|
||||||
|
id(new PHUIInfoView())
|
||||||
|
->setSeverity(PHUIInfoView::SEVERITY_WARNING)
|
||||||
|
->setErrors(array($message)));
|
||||||
|
}
|
||||||
|
|
||||||
return $corpus;
|
return $corpus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -851,6 +869,7 @@ final class DiffusionBrowseController extends DiffusionController {
|
||||||
$show_blame) {
|
$show_blame) {
|
||||||
|
|
||||||
$drequest = $this->getDiffusionRequest();
|
$drequest = $this->getDiffusionRequest();
|
||||||
|
$repository = $drequest->getRepository();
|
||||||
|
|
||||||
$handles = array();
|
$handles = array();
|
||||||
if ($blame) {
|
if ($blame) {
|
||||||
|
@ -989,8 +1008,6 @@ final class DiffusionBrowseController extends DiffusionController {
|
||||||
}
|
}
|
||||||
$handles = $this->loadViewerHandles($phids);
|
$handles = $this->loadViewerHandles($phids);
|
||||||
|
|
||||||
Javelin::initBehavior('phabricator-oncopy', array());
|
|
||||||
|
|
||||||
$engine = null;
|
$engine = null;
|
||||||
$inlines = array();
|
$inlines = array();
|
||||||
if ($this->getRequest()->getStr('lint') !== null && $this->lintMessages) {
|
if ($this->getRequest()->getStr('lint') !== null && $this->lintMessages) {
|
||||||
|
@ -1021,13 +1038,21 @@ final class DiffusionBrowseController extends DiffusionController {
|
||||||
(bool)$this->coverage,
|
(bool)$this->coverage,
|
||||||
$engine);
|
$engine);
|
||||||
|
|
||||||
|
// NOTE: We're doing this manually because rendering is otherwise
|
||||||
|
// dominated by URI generation for very large files.
|
||||||
|
$line_base = (string)$repository->generateURI(
|
||||||
|
array(
|
||||||
|
'action' => 'browse',
|
||||||
|
'stable' => true,
|
||||||
|
));
|
||||||
|
|
||||||
|
require_celerity_resource('aphront-tooltip-css');
|
||||||
|
Javelin::initBehavior('phabricator-oncopy');
|
||||||
|
Javelin::initBehavior('phabricator-tooltips');
|
||||||
|
Javelin::initBehavior('phabricator-line-linker');
|
||||||
|
|
||||||
foreach ($display as $line) {
|
foreach ($display as $line) {
|
||||||
$line_href = $drequest->generateURI(
|
$line_href = $line_base.'$'.$line['line'];
|
||||||
array(
|
|
||||||
'action' => 'browse',
|
|
||||||
'line' => $line['line'],
|
|
||||||
'stable' => true,
|
|
||||||
));
|
|
||||||
|
|
||||||
$blame = array();
|
$blame = array();
|
||||||
$style = null;
|
$style = null;
|
||||||
|
@ -1051,9 +1076,6 @@ final class DiffusionBrowseController extends DiffusionController {
|
||||||
$tooltip = null;
|
$tooltip = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Javelin::initBehavior('phabricator-tooltips', array());
|
|
||||||
require_celerity_resource('aphront-tooltip-css');
|
|
||||||
|
|
||||||
$commit_link = javelin_tag(
|
$commit_link = javelin_tag(
|
||||||
'a',
|
'a',
|
||||||
array(
|
array(
|
||||||
|
@ -1095,19 +1117,23 @@ final class DiffusionBrowseController extends DiffusionController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$uri = $line_href->alter('before', $commit);
|
if ($commit) {
|
||||||
$before_link = javelin_tag(
|
$identifier = $commit->getCommitIdentifier();
|
||||||
'a',
|
$skip_href = $line_href.'?before='.$identifier.'&view=blame';
|
||||||
array(
|
|
||||||
'href' => $uri->setQueryParam('view', 'blame'),
|
$before_link = javelin_tag(
|
||||||
'sigil' => 'has-tooltip',
|
'a',
|
||||||
'meta' => array(
|
array(
|
||||||
'tip' => pht('Skip Past This Commit'),
|
'href' => $skip_href,
|
||||||
'align' => 'E',
|
'sigil' => 'has-tooltip',
|
||||||
'size' => 300,
|
'meta' => array(
|
||||||
|
'tip' => pht('Skip Past This Commit'),
|
||||||
|
'align' => 'E',
|
||||||
|
'size' => 300,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
"\xC2\xAB");
|
||||||
"\xC2\xAB");
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$blame[] = phutil_tag(
|
$blame[] = phutil_tag(
|
||||||
|
@ -1149,8 +1175,6 @@ final class DiffusionBrowseController extends DiffusionController {
|
||||||
),
|
),
|
||||||
$line_link);
|
$line_link);
|
||||||
|
|
||||||
Javelin::initBehavior('phabricator-line-linker');
|
|
||||||
|
|
||||||
if ($line['target']) {
|
if ($line['target']) {
|
||||||
Javelin::initBehavior(
|
Javelin::initBehavior(
|
||||||
'diffusion-jump-to',
|
'diffusion-jump-to',
|
||||||
|
|
|
@ -41,7 +41,6 @@ final class PHUIInfoView extends AphrontView {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addButton(PHUIButtonView $button) {
|
public function addButton(PHUIButtonView $button) {
|
||||||
|
|
||||||
$this->buttons[] = $button;
|
$this->buttons[] = $button;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue