-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimizations #19
Optimizations #19
Commits on Sep 7, 2019
-
Optimization: don't create new hash in Renderer#escape
Renderer#escape was each time passing a new hash instance to gsub, making it allocate more memory than neccessary. Moving the hash to a constant improves performance a bit. For `Markd.to_html("hello world")` before 350.46k ( 2.85µs) (± 6.31%) 4.09kB/op after 431.05k ( 2.32µs) (± 1.43%) 3.07kB/op
Configuration menu - View commit details
-
Copy full SHA for 48935f3 - Browse repository at this point
Copy the full SHA 48935f3View commit details -
Optimization: avoid calling gsub when not needed
For `Markd.to_html("hello world")` before 431.05k ( 2.32µs) (± 1.43%) 3.07kB/op after 506.43k ( 1.97µs) (± 2.50%) 2.72kB/op
Configuration menu - View commit details
-
Copy full SHA for 66c6ea0 - Browse repository at this point
Copy the full SHA 66c6ea0View commit details -
Optimization: avoid creating attributes Hash if not needed
For `Markd.to_html("hello world")` before 506.43k ( 1.97µs) (± 2.50%) 2.72kB/op after 554.18k ( 1.80µs) (± 1.10%) 2.41kB/op
Configuration menu - View commit details
-
Copy full SHA for 530de4c - Browse repository at this point
Copy the full SHA 530de4cView commit details -
Optimization: avoid creating openers_bottom Hash if not needed
For `Markd.to_html("hello world")`: before 554.18k ( 1.80µs) (± 1.10%) 2.41kB/op after 640.45k ( 1.56µs) (± 6.70%) 2.06kB/op
Configuration menu - View commit details
-
Copy full SHA for 92f850e - Browse repository at this point
Copy the full SHA 92f850eView commit details -
Optimization: make Node#data be lazily initialized
This avoids initializing a Hash when not needed. For `Markd.to_html("hello world")`: before 640.45k ( 1.56µs) (± 6.70%) 2.06kB/op after 727.39k ( 1.37µs) (± 2.28%) 1.59kB/op
Configuration menu - View commit details
-
Copy full SHA for c096d59 - Browse repository at this point
Copy the full SHA c096d59View commit details -
Optimization: extract array literal to constant
Array literals in tight loops allocate a lot of memory! Parsing markd's README.md: before 3.52k (283.87µs) (± 0.59%) 259kB/op after 3.66k (273.38µs) (± 0.54%) 244kB/op
Configuration menu - View commit details
-
Copy full SHA for 795b0ff - Browse repository at this point
Copy the full SHA 795b0ffView commit details -
Optimization: avoid double regex match
For `Markd.to_html("hello world")`: before 726.36k ( 1.38µs) (± 1.86%) 1.59kB/op after 800.81k ( 1.25µs) (± 0.58%) 1.58kB/op
Configuration menu - View commit details
-
Copy full SHA for 4a8e485 - Browse repository at this point
Copy the full SHA 4a8e485View commit details -
Optimization: work at the byte level
Markdown is an ASCII format: all control characters are ASCII so we can avoid decoding unicode characters when not needed. The old code was indexing bytes by unicode index position which is very slow because the string must be decoded each time. Here we change it to index by byte, and change all operations to do byte slices instead of unicode slices. For markd's README.md: before 3.86k (258.86µs) (± 0.52%) 242kB/op after 4.11k (243.25µs) (± 1.37%) 242kB/op
Configuration menu - View commit details
-
Copy full SHA for eb17b25 - Browse repository at this point
Copy the full SHA eb17b25View commit details -
Optimization: perform MAIN rule by hand
For `Markd.to_html("hello world")`: before 800.81k ( 1.25µs) (± 0.58%) 1.58kB/op after 829.33k ( 1.21µs) (±25.35%) 1.56kB/op
Configuration menu - View commit details
-
Copy full SHA for 938ae0e - Browse repository at this point
Copy the full SHA 938ae0eView commit details -
Optimization: avoid allocating unnecessary arrays
We can use an inline comparison or a tuple. For markd's README.md: before 4.57k (218.68µs) (± 0.64%) 198kB/op after 4.63k (215.84µs) (± 2.20%) 196kB/op
Configuration menu - View commit details
-
Copy full SHA for e3d247e - Browse repository at this point
Copy the full SHA e3d247eView commit details -
Configuration menu - View commit details
-
Copy full SHA for e451a58 - Browse repository at this point
Copy the full SHA e451a58View commit details -
Optimization: use
each_value
instead ofvalues.each
`values.each` will create an intermediary array
Configuration menu - View commit details
-
Copy full SHA for ee76396 - Browse repository at this point
Copy the full SHA ee76396View commit details -
Configuration menu - View commit details
-
Copy full SHA for 8540dda - Browse repository at this point
Copy the full SHA 8540ddaView commit details -
Configuration menu - View commit details
-
Copy full SHA for c0eb22f - Browse repository at this point
Copy the full SHA c0eb22fView commit details -
Optimization: there's no need to create an array of lines
We can use `each_line` instead of `lines` and then iterating. For `Markd.to_html("hello world")`: before 882.84k ( 1.13µs) (± 1.46%) 1.56kB/op after 929.11k ( 1.08µs) (± 2.75%) 1.46kB/op For markd's README.md: before 4.85k (206.37µs) (± 2.24%) 187kB/op after 4.98k (200.82µs) (± 0.47%) 183kB/op
Configuration menu - View commit details
-
Copy full SHA for 476ef2b - Browse repository at this point
Copy the full SHA 476ef2bView commit details -
Configuration menu - View commit details
-
Copy full SHA for 86c700d - Browse repository at this point
Copy the full SHA 86c700dView commit details -
Optimization: use
String::Builder
instead ofIO::Memory
`String::Builder` is slightly faster when used for a one-time shot.
Configuration menu - View commit details
-
Copy full SHA for fb8048d - Browse repository at this point
Copy the full SHA fb8048dView commit details -
Optimization: for escape chars we can use bytes
Because all escape chars are ASCII it's fine if we go byte per byte. For `Markd.to_html("hello world")`: before 942.28k ( 1.06µs) (± 5.45%) 1.46kB/op after 959.11k ( 1.04µs) (± 0.72%) 1.46kB/op For markd's README.md: before 4.97k (201.41µs) (± 0.74%) 176kB/op after 5.05k (197.95µs) (± 1.51%) 176kB/op
Configuration menu - View commit details
-
Copy full SHA for 408ab49 - Browse repository at this point
Copy the full SHA 408ab49View commit details -
Configuration menu - View commit details
-
Copy full SHA for ba9d8c4 - Browse repository at this point
Copy the full SHA ba9d8c4View commit details -
Configuration menu - View commit details
-
Copy full SHA for ab2a2d1 - Browse repository at this point
Copy the full SHA ab2a2d1View commit details
Commits on Sep 8, 2019
-
Configuration menu - View commit details
-
Copy full SHA for 5e9d34c - Browse repository at this point
Copy the full SHA 5e9d34cView commit details -
Configuration menu - View commit details
-
Copy full SHA for 1f83e56 - Browse repository at this point
Copy the full SHA 1f83e56View commit details -
Configuration menu - View commit details
-
Copy full SHA for 80ae327 - Browse repository at this point
Copy the full SHA 80ae327View commit details -
Configuration menu - View commit details
-
Copy full SHA for 16ed2f6 - Browse repository at this point
Copy the full SHA 16ed2f6View commit details -
Configuration menu - View commit details
-
Copy full SHA for 8688ebb - Browse repository at this point
Copy the full SHA 8688ebbView commit details -
Optimization: avoid gsub if not needed in decode_uri
For markd's README.md: before 5.14k (194.65µs) (± 1.25%) 174kB/op after 5.23k (191.14µs) (± 0.55%) 173kB/op
Configuration menu - View commit details
-
Copy full SHA for 50ee837 - Browse repository at this point
Copy the full SHA 50ee837View commit details