wattsi icon indicating copy to clipboard operation
wattsi copied to clipboard

SplitInHalf is expensive, should use ropes

Open zcorpan opened this issue 9 years ago • 1 comments

See https://github.com/whatwg/wattsi/pull/39#discussion_r94669828

zcorpan avatar Jan 05 '17 06:01 zcorpan

With #39 and with this diff to whatwg/html-build:

diff --git a/build.sh b/build.sh
index 24f30d6..7669382 100755
--- a/build.sh
+++ b/build.sh
@@ -369,7 +369,7 @@ function runWattsi {
   fi
 }
 
-runWattsi $HTML_TEMP/source-whatwg-complete $HTML_TEMP/wattsi-output
+time runWattsi $HTML_TEMP/source-whatwg-complete $HTML_TEMP/wattsi-output
 if [ "$WATTSI_RESULT" == "0" ]; then
     $QUIET || cat $HTML_TEMP/wattsi-output.txt | grep -v '^$' # trim blank lines
 else

I get, running ./build.sh -n a few times:

real	0m6.539s
user	0m5.740s
sys	0m0.566s

real	0m6.317s
user	0m5.652s
sys	0m0.513s

real	0m6.198s
user	0m5.619s
sys	0m0.492s

and then with current master (i.e. without #39):

real	0m6.210s
user	0m5.618s
sys	0m0.504s

real	0m6.296s
user	0m5.677s
sys	0m0.519s

real	0m6.357s
user	0m5.679s
sys	0m0.534s

Seems like it did not regress noticeably at least.

With the following diff on #39:

diff --git a/src/wattsi.pas b/src/wattsi.pas
index 1ac317a..53d7148 100644
--- a/src/wattsi.pas
+++ b/src/wattsi.pas
@@ -2017,6 +2017,7 @@ begin
   Result := i > 0;
   if Result then
   begin
+    Inform('SplitInHalf: ' + Txt);
     Half1 := Copy(Txt, 1, i-1);
     Half2 := Copy(Txt, i+Length(Separator), Length(Txt));
   end;

I get 755 rows logged. But only 11 after removing duplicate lines. So an alternative optimization could be to cache the result maybe?

zcorpan avatar Jan 05 '17 09:01 zcorpan