@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+54 -31
+54 -30
src/applications/diffusion/controller/DiffusionBrowseController.php
··· 585 585 } 586 586 587 587 $file_corpus = $file_content->getCorpus(); 588 + $highlight_limit = DifferentialChangesetParser::HIGHLIGHT_BYTE_LIMIT; 589 + $can_highlight = (strlen($file_corpus) <= $highlight_limit); 588 590 589 591 if (!$show_color) { 590 592 $lines = phutil_split_lines($file_corpus); ··· 625 627 implode('', $rows)); 626 628 } 627 629 } else { 628 - require_celerity_resource('syntax-highlighting-css'); 630 + if ($can_highlight) { 631 + require_celerity_resource('syntax-highlighting-css'); 629 632 630 - $highlighted = PhabricatorSyntaxHighlighter::highlightWithFilename( 631 - $path, 632 - $file_corpus); 633 - $lines = phutil_split_lines($highlighted); 633 + $highlighted = PhabricatorSyntaxHighlighter::highlightWithFilename( 634 + $path, 635 + $file_corpus); 636 + $lines = phutil_split_lines($highlighted); 637 + } else { 638 + $lines = phutil_split_lines($file_corpus); 639 + } 634 640 635 641 $rows = $this->buildDisplayRows( 636 642 $lines, ··· 706 712 ->appendChild($corpus) 707 713 ->setCollapsed(true); 708 714 715 + if (!$can_highlight) { 716 + $message = pht( 717 + 'This file is larger than %s, so syntax highlighting is disabled '. 718 + 'by default.', 719 + phutil_format_bytes($highlight_limit)); 720 + 721 + $corpus->setInfoView( 722 + id(new PHUIInfoView()) 723 + ->setSeverity(PHUIInfoView::SEVERITY_WARNING) 724 + ->setErrors(array($message))); 725 + } 726 + 709 727 return $corpus; 710 728 } 711 729 ··· 851 869 $show_blame) { 852 870 853 871 $drequest = $this->getDiffusionRequest(); 872 + $repository = $drequest->getRepository(); 854 873 855 874 $handles = array(); 856 875 if ($blame) { ··· 989 1008 } 990 1009 $handles = $this->loadViewerHandles($phids); 991 1010 992 - Javelin::initBehavior('phabricator-oncopy', array()); 993 - 994 1011 $engine = null; 995 1012 $inlines = array(); 996 1013 if ($this->getRequest()->getStr('lint') !== null && $this->lintMessages) { ··· 1021 1038 (bool)$this->coverage, 1022 1039 $engine); 1023 1040 1041 + // NOTE: We're doing this manually because rendering is otherwise 1042 + // dominated by URI generation for very large files. 1043 + $line_base = (string)$repository->generateURI( 1044 + array( 1045 + 'action' => 'browse', 1046 + 'stable' => true, 1047 + )); 1048 + 1049 + require_celerity_resource('aphront-tooltip-css'); 1050 + Javelin::initBehavior('phabricator-oncopy'); 1051 + Javelin::initBehavior('phabricator-tooltips'); 1052 + Javelin::initBehavior('phabricator-line-linker'); 1053 + 1024 1054 foreach ($display as $line) { 1025 - $line_href = $drequest->generateURI( 1026 - array( 1027 - 'action' => 'browse', 1028 - 'line' => $line['line'], 1029 - 'stable' => true, 1030 - )); 1055 + $line_href = $line_base.'$'.$line['line']; 1031 1056 1032 1057 $blame = array(); 1033 1058 $style = null; ··· 1050 1075 } else { 1051 1076 $tooltip = null; 1052 1077 } 1053 - 1054 - Javelin::initBehavior('phabricator-tooltips', array()); 1055 - require_celerity_resource('aphront-tooltip-css'); 1056 1078 1057 1079 $commit_link = javelin_tag( 1058 1080 'a', ··· 1095 1117 } 1096 1118 } 1097 1119 1098 - $uri = $line_href->alter('before', $commit); 1099 - $before_link = javelin_tag( 1100 - 'a', 1101 - array( 1102 - 'href' => $uri->setQueryParam('view', 'blame'), 1103 - 'sigil' => 'has-tooltip', 1104 - 'meta' => array( 1105 - 'tip' => pht('Skip Past This Commit'), 1106 - 'align' => 'E', 1107 - 'size' => 300, 1120 + if ($commit) { 1121 + $identifier = $commit->getCommitIdentifier(); 1122 + $skip_href = $line_href.'?before='.$identifier.'&view=blame'; 1123 + 1124 + $before_link = javelin_tag( 1125 + 'a', 1126 + array( 1127 + 'href' => $skip_href, 1128 + 'sigil' => 'has-tooltip', 1129 + 'meta' => array( 1130 + 'tip' => pht('Skip Past This Commit'), 1131 + 'align' => 'E', 1132 + 'size' => 300, 1133 + ), 1108 1134 ), 1109 - ), 1110 - "\xC2\xAB"); 1135 + "\xC2\xAB"); 1136 + } 1111 1137 } 1112 1138 1113 1139 $blame[] = phutil_tag( ··· 1148 1174 'style' => $style, 1149 1175 ), 1150 1176 $line_link); 1151 - 1152 - Javelin::initBehavior('phabricator-line-linker'); 1153 1177 1154 1178 if ($line['target']) { 1155 1179 Javelin::initBehavior(
-1
src/view/form/PHUIInfoView.php
··· 41 41 } 42 42 43 43 public function addButton(PHUIButtonView $button) { 44 - 45 44 $this->buttons[] = $button; 46 45 return $this; 47 46 }