Skip to content

Conversation

@ashmaroli
Copy link
Contributor

Rationale

It is wasteful to allocate /`/ and /`\Z/ every time a simple codespan is parsed. Instead use a static regex which is allocated only once each.

Context

Results from profiling Jekyll docs:

Before

Total allocated: 158.07 MB (1168216 objects)
Total retained:  10.3 MB (92547 objects)

After

Total allocated: 157.1 MB (1162835 objects)
Total retained:  10.3 MB (92547 objects)

@ashmaroli ashmaroli force-pushed the simple-static-regex branch from 9867a3b to 2bf7b36 Compare May 23, 2019 14:37
@ashmaroli
Copy link
Contributor Author

Profiler Diff Summary

--- master branch https://travis-ci.org/gettalong/kramdown/jobs/536192573
+++ PR branch     https://travis-ci.org/gettalong/kramdown/jobs/536323986

- Total allocated: 220.89 MB (1783975 objects)
+ Total allocated: 219.34 MB (1775370 objects)
  Total retained:  1.11 MB (1582 objects)

To avoid generating another set of regex and matchdata


Co-authored-by: Thomas Leitner <t_leitner@gmx.at>
@ashmaroli
Copy link
Contributor Author

@gettalong I guess we were wrong. The latest change isn't synonymous with the existing behavior:

irb(main):001:0> string = "`foobar`\n"
=> "`foobar`\n"

irb(main):002:0> string.sub(/`\Z/, '')
=> "`foobar\n"

irb(main):003:0> string.chomp('`')
=> "`foobar`\n"

irb(main):004:0> string.sub(/`\Z/, '') == string.chomp('`')
=> false

Shall I revert the latest commit or am I testing incorrectly?

@gettalong
Copy link
Owner

You are right, \Z matches before a new line at the end, \z matches at the end. I guess the original version it is.

@ashmaroli
Copy link
Contributor Author

@gettalong Pinging you as a gentle reminder...

@gettalong
Copy link
Owner

@ashmaroli Sorry for the delay, I will find some time in the coming days for kramdown.

@gettalong
Copy link
Owner

@ashmaroli Even though the winnings are not much, the changes are not very invasive and I will therefore accept them.

@gettalong gettalong closed this Apr 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants