Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding.html: optimize escape performance #19264

Merged

Conversation

ttytm
Copy link
Member

@ttytm ttytm commented Sep 3, 2023

Using constants instead of re-allocating the array results in an performance improvement of about 30%.

Tested with 100k iterations:
current: 84.042ms
consts: 58.604ms

Additionally, it replaces '"' with '"' and ''' with '''.
The values are the common replacements for " and ', e.g. also used for escaping in Go.

馃 Generated by Copilot at 435ad5b

Refactor escape function in encoding/html module to use constant arrays.

馃 Generated by Copilot at 435ad5b

  • Define constant arrays html_escape_table and html_escape_table_len to store the HTML replacement characters for the escape function (link)
  • Replace the literal arrays with the constant arrays in the escape function, making it more consistent and concise (link)

@ttytm ttytm marked this pull request as draft September 3, 2023 13:54
@ttytm ttytm force-pushed the encoding.html/optimize-escape-performance branch from 435ad5b to 5926aa9 Compare September 3, 2023 13:57
@ttytm ttytm marked this pull request as ready for review September 3, 2023 13:58
Copy link
Member

@spytheman spytheman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work.

@spytheman spytheman merged commit 61b2199 into vlang:master Sep 3, 2023
35 checks passed
Wertzui123 pushed a commit to Wertzui123/v that referenced this pull request Oct 8, 2023
@ttytm ttytm deleted the encoding.html/optimize-escape-performance branch December 15, 2023 22:08
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.

None yet

2 participants