@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 performance of generating synthetic changesets

Summary: Ref T7776. This could get better, but I think I got most of the big stuff. It's ~4x faster now.

Test Plan:
Before:

{F393338}

After:

{F393339}

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T7776

Differential Revision: https://secure.phabricator.com/D12730

+42 -15
+19 -7
src/applications/differential/parser/DifferentialHunkParser.php
··· 418 418 $old_lines = array(); 419 419 $new_lines = array(); 420 420 foreach ($hunks as $hunk) { 421 - 422 - $lines = $hunk->getChanges(); 423 - $lines = phutil_split_lines($lines); 421 + $lines = $hunk->getSplitLines(); 424 422 425 423 $line_type_map = array(); 426 424 $line_text = array(); ··· 514 512 // Put changes side by side. 515 513 $olds = array(); 516 514 $news = array(); 515 + $olds_cursor = -1; 516 + $news_cursor = -1; 517 517 foreach ($changeset_hunks as $hunk) { 518 518 $n_old = $hunk->getOldOffset(); 519 519 $n_new = $hunk->getNewOffset(); 520 - $changes = phutil_split_lines($hunk->getChanges()); 520 + $changes = $hunk->getSplitLines(); 521 521 foreach ($changes as $line) { 522 522 $diff_type = $line[0]; // Change type in diff of diffs. 523 523 $orig_type = $line[1]; // Change type in the original diff. 524 524 if ($diff_type == ' ') { 525 525 // Use the same key for lines that are next to each other. 526 - $key = max(last_key($olds), last_key($news)) + 1; 526 + if ($olds_cursor > $news_cursor) { 527 + $key = $olds_cursor + 1; 528 + } else { 529 + $key = $news_cursor + 1; 530 + } 527 531 $olds[$key] = null; 528 532 $news[$key] = null; 533 + $olds_cursor = $key; 534 + $news_cursor = $key; 529 535 } else if ($diff_type == '-') { 530 536 $olds[] = array($n_old, $orig_type); 537 + $olds_cursor++; 531 538 } else if ($diff_type == '+') { 532 539 $news[] = array($n_new, $orig_type); 540 + $news_cursor++; 533 541 } 534 542 if (($diff_type == '-' || $diff_type == ' ') && $orig_type != '-') { 535 543 $n_old++; ··· 660 668 $offsets = array(); 661 669 $n = 1; 662 670 foreach ($hunks as $hunk) { 663 - for ($i = 0; $i < $hunk->getNewLen(); $i++) { 664 - $offsets[$n] = $hunk->getNewOffset() + $i; 671 + $new_length = $hunk->getNewLen(); 672 + $new_offset = $hunk->getNewOffset(); 673 + 674 + for ($i = 0; $i < $new_length; $i++) { 675 + $offsets[$n] = $new_offset + $i; 665 676 $n++; 666 677 } 667 678 } 679 + 668 680 return $offsets; 669 681 } 670 682 }
+23 -8
src/applications/differential/storage/DifferentialHunk.php
··· 10 10 protected $newLen; 11 11 12 12 private $changeset; 13 + private $splitLines; 13 14 private $structuredLines; 14 15 private $structuredFiles = array(); 15 16 ··· 109 110 return $this->structuredFiles[$kind]; 110 111 } 111 112 113 + public function getSplitLines() { 114 + if ($this->splitLines === null) { 115 + $this->splitLines = phutil_split_lines($this->getChanges()); 116 + } 117 + return $this->splitLines; 118 + } 119 + 112 120 private function getStructuredLines() { 113 121 if ($this->structuredLines === null) { 114 - $lines = phutil_split_lines($this->getChanges()); 122 + $lines = $this->getSplitLines(); 115 123 116 124 $structured = array(); 117 125 foreach ($lines as $line) { ··· 154 162 } 155 163 156 164 final private function makeContent($include) { 165 + $lines = $this->getSplitLines(); 157 166 $results = array(); 158 - $lines = explode("\n", $this->getChanges()); 159 167 168 + $include_map = array(); 169 + for ($ii = 0; $ii < strlen($include); $ii++) { 170 + $include_map[$include[$ii]] = true; 171 + } 160 172 161 - $n = (strpos($include, '+') !== false ? 162 - $this->newOffset : 163 - $this->oldOffset); 173 + if (isset($include_map['+'])) { 174 + $n = $this->newOffset; 175 + } else { 176 + $n = $this->oldOffset; 177 + } 178 + 164 179 $use_next_newline = false; 165 180 foreach ($lines as $line) { 166 181 if (!isset($line[0])) { ··· 171 186 if ($use_next_newline) { 172 187 $results[last_key($results)] = rtrim(end($results), "\n"); 173 188 } 174 - } else if (strpos($include, $line[0]) === false) { 189 + } else if (empty($include_map[$line[0]])) { 175 190 $use_next_newline = false; 176 191 } else { 177 192 $use_next_newline = true; 178 - $results[$n] = substr($line, 1)."\n"; 193 + $results[$n] = substr($line, 1); 179 194 } 180 195 181 - if ($line[0] == ' ' || strpos($include, $line[0]) !== false) { 196 + if ($line[0] == ' ' || isset($include_map[$line[0]])) { 182 197 $n++; 183 198 } 184 199 }