@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.

Count lines in build log slices more cheaply

Summary:
See PHI766. Ref T13164. Build log chunk processing does a `preg_split()` on slices, but this isn't terribly efficient.

We can get the same count more cheaply by just using `substr_count()` a few times.

(I also tried `preg_match_all()`, which was between the two in speed.)

Test Plan:
- Used `bin/harbormaster rebuild-log --id X --force` to rebuild logs. Verified that the linemap is identical before/after this change.
- Saw local time for the 18MB log in PHI766 drop from ~1.7s to ~900ms, and `preg_split()` drop out of the profiler (we're now spending the biggest chunk of time on `gzdeflate()`).

Reviewers: amckinley

Reviewed By: amckinley

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13164

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

+7 -1
+7 -1
src/applications/harbormaster/storage/build/HarbormasterBuildLog.php
··· 643 643 $pos += $slice_length; 644 644 645 645 $map_bytes += $slice_length; 646 - $line_count += count(preg_split("/\r\n|\r|\n/", $slice)) - 1; 646 + 647 + // Count newlines in the slice. This goofy approach is meaningfully 648 + // faster than "preg_match_all()" or "preg_split()". See PHI766. 649 + $n_rn = substr_count($slice, "\r\n"); 650 + $n_r = substr_count($slice, "\r"); 651 + $n_n = substr_count($slice, "\n"); 652 + $line_count += ($n_rn) + ($n_r - $n_rn) + ($n_n - $n_rn); 647 653 648 654 if ($map_bytes >= ($marker_distance - $max_utf8_width)) { 649 655 $map[] = array(