tracking-perf.md

  1## Tracking perf changes
  2
  3Initial performance:
  4```
  5goos: darwin
  6goarch: amd64
  7pkg: github.com/gomarkdown/markdown
  8BenchmarkEscapeHTML-8                           	 2000000	       823 ns/op	       0 B/op	       0 allocs/op
  9BenchmarkSmartDoubleQuotes-8                    	  300000	      5033 ns/op	    9872 B/op	      56 allocs/op
 10BenchmarkReferenceAmps-8                        	  100000	     19538 ns/op	   26776 B/op	     150 allocs/op
 11BenchmarkReferenceAutoLinks-8                   	  100000	     17574 ns/op	   24544 B/op	     132 allocs/op
 12BenchmarkReferenceBackslashEscapes-8            	   30000	     50977 ns/op	   76752 B/op	     243 allocs/op
 13BenchmarkReferenceBlockquotesWithCodeBlocks-8   	  200000	      8546 ns/op	   12864 B/op	      65 allocs/op
 14BenchmarkReferenceCodeBlocks-8                  	  200000	      9000 ns/op	   14912 B/op	      70 allocs/op
 15BenchmarkReferenceCodeSpans-8                   	  200000	      8856 ns/op	   14992 B/op	      69 allocs/op
 16BenchmarkReferenceHardWrappedPara-8             	  200000	      6599 ns/op	   11312 B/op	      57 allocs/op
 17BenchmarkReferenceHorizontalRules-8             	  100000	     15483 ns/op	   23536 B/op	      98 allocs/op
 18BenchmarkReferenceInlineHTMLAdvances-8          	  200000	      6839 ns/op	   12150 B/op	      62 allocs/op
 19BenchmarkReferenceInlineHTMLSimple-8            	  100000	     19940 ns/op	   28488 B/op	     117 allocs/op
 20BenchmarkReferenceInlineHTMLComments-8          	  200000	      7455 ns/op	   13440 B/op	      64 allocs/op
 21BenchmarkReferenceLinksInline-8                 	  100000	     16425 ns/op	   23664 B/op	     147 allocs/op
 22BenchmarkReferenceLinksReference-8              	   30000	     54895 ns/op	   66464 B/op	     416 allocs/op
 23BenchmarkReferenceLinksShortcut-8               	  100000	     17647 ns/op	   23776 B/op	     158 allocs/op
 24BenchmarkReferenceLiterQuotesInTitles-8         	  200000	      9367 ns/op	   14832 B/op	      95 allocs/op
 25BenchmarkReferenceMarkdownBasics-8              	   10000	    129772 ns/op	  130848 B/op	     378 allocs/op
 26BenchmarkReferenceMarkdownSyntax-8              	    3000	    502365 ns/op	  461411 B/op	    1411 allocs/op
 27BenchmarkReferenceNestedBlockquotes-8           	  200000	      7028 ns/op	   12688 B/op	      64 allocs/op
 28BenchmarkReferenceOrderedAndUnorderedLists-8    	   20000	     79686 ns/op	  107520 B/op	     374 allocs/op
 29BenchmarkReferenceStrongAndEm-8                 	  200000	     10020 ns/op	   17792 B/op	      78 allocs/op
 30BenchmarkReferenceTabs-8                        	  200000	     12025 ns/op	   18224 B/op	      81 allocs/op
 31BenchmarkReferenceTidyness-8                    	  200000	      8985 ns/op	   14432 B/op	      71 allocs/op
 32PASS
 33ok  	github.com/gomarkdown/markdown	45.375s
 34```
 35
 36After switching to using interface{} for Node.Data:
 37```
 38BenchmarkEscapeHTML-8                           	 2000000	       929 ns/op	       0 B/op	       0 allocs/op
 39BenchmarkSmartDoubleQuotes-8                    	  300000	      5126 ns/op	    9248 B/op	      56 allocs/op
 40BenchmarkReferenceAmps-8                        	  100000	     19927 ns/op	   17880 B/op	     154 allocs/op
 41BenchmarkReferenceAutoLinks-8                   	  100000	     20732 ns/op	   17360 B/op	     141 allocs/op
 42BenchmarkReferenceBackslashEscapes-8            	   30000	     50267 ns/op	   38128 B/op	     244 allocs/op
 43BenchmarkReferenceBlockquotesWithCodeBlocks-8   	  200000	      8988 ns/op	   10912 B/op	      67 allocs/op
 44BenchmarkReferenceCodeBlocks-8                  	  200000	      8611 ns/op	   12256 B/op	      74 allocs/op
 45BenchmarkReferenceCodeSpans-8                   	  200000	      8256 ns/op	   11248 B/op	      69 allocs/op
 46BenchmarkReferenceHardWrappedPara-8             	  200000	      6739 ns/op	    9856 B/op	      57 allocs/op
 47BenchmarkReferenceHorizontalRules-8             	  100000	     15503 ns/op	   15600 B/op	     104 allocs/op
 48BenchmarkReferenceInlineHTMLAdvances-8          	  200000	      6874 ns/op	   10278 B/op	      62 allocs/op
 49BenchmarkReferenceInlineHTMLSimple-8            	  100000	     22271 ns/op	   18552 B/op	     121 allocs/op
 50BenchmarkReferenceInlineHTMLComments-8          	  200000	      8315 ns/op	   10736 B/op	      64 allocs/op
 51BenchmarkReferenceLinksInline-8                 	  100000	     16155 ns/op	   16912 B/op	     152 allocs/op
 52BenchmarkReferenceLinksReference-8              	   30000	     52387 ns/op	   38192 B/op	     445 allocs/op
 53BenchmarkReferenceLinksShortcut-8               	  100000	     17111 ns/op	   16592 B/op	     167 allocs/op
 54BenchmarkReferenceLiterQuotesInTitles-8         	  200000	      9164 ns/op	   12048 B/op	      97 allocs/op
 55BenchmarkReferenceMarkdownBasics-8              	   10000	    129262 ns/op	   87264 B/op	     416 allocs/op
 56BenchmarkReferenceMarkdownSyntax-8              	    3000	    496873 ns/op	  293906 B/op	    1559 allocs/op
 57BenchmarkReferenceNestedBlockquotes-8           	  200000	      6854 ns/op	   10192 B/op	      64 allocs/op
 58BenchmarkReferenceOrderedAndUnorderedLists-8    	   20000	     79633 ns/op	   55024 B/op	     447 allocs/op
 59BenchmarkReferenceStrongAndEm-8                 	  200000	      9637 ns/op	   12176 B/op	      78 allocs/op
 60BenchmarkReferenceTabs-8                        	  100000	     12164 ns/op	   13776 B/op	      87 allocs/op
 61BenchmarkReferenceTidyness-8                    	  200000	      8677 ns/op	   11296 B/op	      75 allocs/op
 62```
 63
 64Not necessarily faster, but uses less bytes per op (but sometimes more allocs).
 65
 66After tweaking the API:
 67```
 68$ ./s/run-bench.sh
 69
 70go test -bench=. -test.benchmem
 71goos: darwin
 72goarch: amd64
 73pkg: github.com/gomarkdown/markdown
 74BenchmarkEscapeHTML-8                           	 2000000	       834 ns/op	       0 B/op	       0 allocs/op
 75BenchmarkSmartDoubleQuotes-8                    	  300000	      3486 ns/op	    6160 B/op	      27 allocs/op
 76BenchmarkReferenceAmps-8                        	  100000	     18158 ns/op	   14792 B/op	     125 allocs/op
 77BenchmarkReferenceAutoLinks-8                   	  100000	     16824 ns/op	   14272 B/op	     112 allocs/op
 78BenchmarkReferenceBackslashEscapes-8            	   30000	     44066 ns/op	   35040 B/op	     215 allocs/op
 79BenchmarkReferenceBlockquotesWithCodeBlocks-8   	  200000	      6868 ns/op	    7824 B/op	      38 allocs/op
 80BenchmarkReferenceCodeBlocks-8                  	  200000	      7157 ns/op	    9168 B/op	      45 allocs/op
 81BenchmarkReferenceCodeSpans-8                   	  200000	      6663 ns/op	    8160 B/op	      40 allocs/op
 82BenchmarkReferenceHardWrappedPara-8             	  300000	      4821 ns/op	    6768 B/op	      28 allocs/op
 83BenchmarkReferenceHorizontalRules-8             	  100000	     13033 ns/op	   12512 B/op	      75 allocs/op
 84BenchmarkReferenceInlineHTMLAdvances-8          	  300000	      4998 ns/op	    7190 B/op	      33 allocs/op
 85BenchmarkReferenceInlineHTMLSimple-8            	  100000	     17696 ns/op	   15464 B/op	      92 allocs/op
 86BenchmarkReferenceInlineHTMLComments-8          	  300000	      5506 ns/op	    7648 B/op	      35 allocs/op
 87BenchmarkReferenceLinksInline-8                 	  100000	     14450 ns/op	   13824 B/op	     123 allocs/op
 88BenchmarkReferenceLinksReference-8              	   30000	     52561 ns/op	   35104 B/op	     416 allocs/op
 89BenchmarkReferenceLinksShortcut-8               	  100000	     15616 ns/op	   13504 B/op	     138 allocs/op
 90BenchmarkReferenceLiterQuotesInTitles-8         	  200000	      7772 ns/op	    8960 B/op	      68 allocs/op
 91BenchmarkReferenceMarkdownBasics-8              	   10000	    121436 ns/op	   84176 B/op	     387 allocs/op
 92BenchmarkReferenceMarkdownSyntax-8              	    3000	    487404 ns/op	  290818 B/op	    1530 allocs/op
 93BenchmarkReferenceNestedBlockquotes-8           	  300000	      5098 ns/op	    7104 B/op	      35 allocs/op
 94BenchmarkReferenceOrderedAndUnorderedLists-8    	   20000	     74422 ns/op	   51936 B/op	     418 allocs/op
 95BenchmarkReferenceStrongAndEm-8                 	  200000	      7888 ns/op	    9088 B/op	      49 allocs/op
 96BenchmarkReferenceTabs-8                        	  200000	     10061 ns/op	   10688 B/op	      58 allocs/op
 97BenchmarkReferenceTidyness-8                    	  200000	      7152 ns/op	    8208 B/op	      46 allocs/op
 98ok  	github.com/gomarkdown/markdown	40.809s
 99```
100
101After refactoring Renderer:
102```
103BenchmarkEscapeHTML-8                                    2000000               883 ns/op               0 B/op          0 allocs/op
104BenchmarkSmartDoubleQuotes-8                              300000              3717 ns/op            6208 B/op         29 allocs/op
105BenchmarkReferenceAmps-8                                  100000             19135 ns/op           14680 B/op        123 allocs/op
106BenchmarkReferenceAutoLinks-8                             100000             17142 ns/op           14176 B/op        110 allocs/op
107BenchmarkReferenceBackslashEscapes-8                       30000             54616 ns/op           35088 B/op        217 allocs/op
108BenchmarkReferenceBlockquotesWithCodeBlocks-8             200000              7993 ns/op            7872 B/op         40 allocs/op
109BenchmarkReferenceCodeBlocks-8                            200000              8285 ns/op            9216 B/op         47 allocs/op
110BenchmarkReferenceCodeSpans-8                             200000              7684 ns/op            8208 B/op         42 allocs/op
111BenchmarkReferenceHardWrappedPara-8                       200000              5595 ns/op            6816 B/op         30 allocs/op
112BenchmarkReferenceHorizontalRules-8                       100000             16444 ns/op           12560 B/op         77 allocs/op
113BenchmarkReferenceInlineHTMLAdvances-8                    200000              5415 ns/op            7238 B/op         35 allocs/op
114BenchmarkReferenceInlineHTMLSimple-8                      100000             19867 ns/op           15512 B/op         94 allocs/op
115BenchmarkReferenceInlineHTMLComments-8                    200000              6026 ns/op            7696 B/op         37 allocs/op
116BenchmarkReferenceLinksInline-8                           100000             14864 ns/op           13664 B/op        120 allocs/op
117BenchmarkReferenceLinksReference-8                         30000             52479 ns/op           34816 B/op        401 allocs/op
118BenchmarkReferenceLinksShortcut-8                         100000             15812 ns/op           13472 B/op        135 allocs/op
119BenchmarkReferenceLiterQuotesInTitles-8                   200000              7767 ns/op            8880 B/op         68 allocs/op
120BenchmarkReferenceMarkdownBasics-8                         10000            131065 ns/op           84048 B/op        386 allocs/op
121BenchmarkReferenceMarkdownSyntax-8                          2000            515604 ns/op          289953 B/op       1501 allocs/op
122BenchmarkReferenceNestedBlockquotes-8                     200000              5655 ns/op            7152 B/op         37 allocs/op
123BenchmarkReferenceOrderedAndUnorderedLists-8               20000             84188 ns/op           51984 B/op        420 allocs/op
124BenchmarkReferenceStrongAndEm-8                           200000              8664 ns/op            9136 B/op         51 allocs/op
125BenchmarkReferenceTabs-8                                  100000             11110 ns/op           10736 B/op         60 allocs/op
126BenchmarkReferenceTidyness-8                              200000              7628 ns/op            8256 B/op         48 allocs/op
127ok      github.com/gomarkdown/markdown  40.841s
128```
129
130After Node refactor to have Children array:
131```
132BenchmarkEscapeHTML-8                                    2000000               901 ns/op               0 B/op          0 allocs/op
133BenchmarkSmartDoubleQuotes-8                              300000              3905 ns/op            6224 B/op         31 allocs/op
134BenchmarkReferenceAmps-8                                  100000             22216 ns/op           15560 B/op        157 allocs/op
135BenchmarkReferenceAutoLinks-8                             100000             20335 ns/op           14824 B/op        146 allocs/op
136BenchmarkReferenceBackslashEscapes-8                       20000             69174 ns/op           37392 B/op        316 allocs/op
137BenchmarkReferenceBlockquotesWithCodeBlocks-8             200000              8443 ns/op            7968 B/op         48 allocs/op
138BenchmarkReferenceCodeBlocks-8                            200000              9250 ns/op            9392 B/op         58 allocs/op
139BenchmarkReferenceCodeSpans-8                             200000              8515 ns/op            8432 B/op         54 allocs/op
140BenchmarkReferenceHardWrappedPara-8                       200000              5738 ns/op            6856 B/op         34 allocs/op
141BenchmarkReferenceHorizontalRules-8                       100000             20864 ns/op           13648 B/op         93 allocs/op
142BenchmarkReferenceInlineHTMLAdvances-8                    200000              6187 ns/op            7310 B/op         40 allocs/op
143BenchmarkReferenceInlineHTMLSimple-8                       50000             23793 ns/op           16128 B/op        114 allocs/op
144BenchmarkReferenceInlineHTMLComments-8                    200000              7060 ns/op            7840 B/op         44 allocs/op
145BenchmarkReferenceLinksInline-8                           100000             18432 ns/op           14496 B/op        153 allocs/op
146BenchmarkReferenceLinksReference-8                         20000             67666 ns/op           37136 B/op        502 allocs/op
147BenchmarkReferenceLinksShortcut-8                         100000             19324 ns/op           13984 B/op        162 allocs/op
148BenchmarkReferenceLiterQuotesInTitles-8                   200000              8998 ns/op            9320 B/op         83 allocs/op
149BenchmarkReferenceMarkdownBasics-8                         10000            160908 ns/op           88152 B/op        518 allocs/op
150BenchmarkReferenceMarkdownSyntax-8                          2000            707160 ns/op          303801 B/op       2044 allocs/op
151BenchmarkReferenceNestedBlockquotes-8                     200000              6740 ns/op            7248 B/op         45 allocs/op
152BenchmarkReferenceOrderedAndUnorderedLists-8               10000            115808 ns/op           55052 B/op        626 allocs/op
153BenchmarkReferenceStrongAndEm-8                           100000             10540 ns/op            9416 B/op         72 allocs/op
154BenchmarkReferenceTabs-8                                  100000             13171 ns/op           10968 B/op         77 allocs/op
155BenchmarkReferenceTidyness-8                              200000              8903 ns/op            8404 B/op         62 allocs/op
156PASS
157ok      github.com/gomarkdown/markdown  43.477s
158```
159It's slower (but opens up possibilities for further improvements).
160
161After refactoring to make ast.Node a top-level thing.
162```
163BenchmarkEscapeHTML-8                                    2000000               829 ns/op               0 B/op          0 allocs/op
164BenchmarkSmartDoubleQuotes-8                              300000              3998 ns/op            6192 B/op         31 allocs/op
165BenchmarkReferenceAmps-8                                   50000             27389 ns/op           15480 B/op        153 allocs/op
166BenchmarkReferenceAutoLinks-8                              50000             23106 ns/op           14656 B/op        137 allocs/op
167BenchmarkReferenceBackslashEscapes-8                       10000            112435 ns/op           36696 B/op        315 allocs/op
168BenchmarkReferenceBlockquotesWithCodeBlocks-8             200000              9227 ns/op            7856 B/op         46 allocs/op
169BenchmarkReferenceCodeBlocks-8                            200000             10469 ns/op            9248 B/op         54 allocs/op
170BenchmarkReferenceCodeSpans-8                             200000             10522 ns/op            8368 B/op         54 allocs/op
171BenchmarkReferenceHardWrappedPara-8                       200000              6354 ns/op            6784 B/op         34 allocs/op
172BenchmarkReferenceHorizontalRules-8                        50000             32393 ns/op           13952 B/op         87 allocs/op
173BenchmarkReferenceInlineHTMLAdvances-8                    200000              6894 ns/op            7238 B/op         40 allocs/op
174BenchmarkReferenceInlineHTMLSimple-8                       50000             32942 ns/op           15864 B/op        110 allocs/op
175BenchmarkReferenceInlineHTMLComments-8                    200000              8181 ns/op            7776 B/op         44 allocs/op
176BenchmarkReferenceLinksInline-8                           100000             21679 ns/op           14400 B/op        148 allocs/op
177BenchmarkReferenceLinksReference-8                         20000             83928 ns/op           36688 B/op        473 allocs/op
178BenchmarkReferenceLinksShortcut-8                         100000             22053 ns/op           13872 B/op        153 allocs/op
179BenchmarkReferenceLiterQuotesInTitles-8                   100000             10784 ns/op            9296 B/op         81 allocs/op
180BenchmarkReferenceMarkdownBasics-8                          5000            237097 ns/op           87760 B/op        480 allocs/op
181BenchmarkReferenceMarkdownSyntax-8                          1000           1465402 ns/op          300769 B/op       1896 allocs/op
182BenchmarkReferenceNestedBlockquotes-8                     200000              7461 ns/op            7152 B/op         45 allocs/op
183BenchmarkReferenceOrderedAndUnorderedLists-8                5000            212256 ns/op           53724 B/op        553 allocs/op
184BenchmarkReferenceStrongAndEm-8                           100000             13018 ns/op            9264 B/op         72 allocs/op
185BenchmarkReferenceTabs-8                                  100000             15005 ns/op           10752 B/op         71 allocs/op
186BenchmarkReferenceTidyness-8                              200000             10308 ns/op            8292 B/op         58 allocs/op
187PASS
188ok      github.com/gomarkdown/markdown  42.176s
189```