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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve parse_declarations! performance #166

Merged

Conversation

leonid-shevtsov
Copy link
Contributor

This PR replaces regexp-matching code in parse_declarations! with equivalent substring lookup using .split(&block) and .index.

On our benchmarks this shows a 10% improvement in performance measured for overall add_rule! / add_block!. So, quite a significant one.

Pre-Merge Checklist

  • CHANGELOG.md updated with short summary

lib/css_parser/rule_set.rb Outdated Show resolved Hide resolved
@leonid-shevtsov leonid-shevtsov force-pushed the improve-parse-declarations-performance branch from 230cc70 to 9b3ac77 Compare August 16, 2024 10:22
@leonid-shevtsov
Copy link
Contributor Author

@grosser I've addressed the comments.

As to the splitting by newline - as I recall, I removed it because newlines are not significant in CSS; only semicolons can split declarations. So, they can be handled as any other whitespace (stripped, that is.)

I added a test, if you have something else in mind, let's test that as well.

lib/css_parser/rule_set.rb Outdated Show resolved Hide resolved
lib/css_parser/rule_set.rb Outdated Show resolved Hide resolved
lib/css_parser/rule_set.rb Outdated Show resolved Hide resolved
lib/css_parser/rule_set.rb Outdated Show resolved Hide resolved
@leonid-shevtsov leonid-shevtsov force-pushed the improve-parse-declarations-performance branch from 9b3ac77 to b4d986a Compare August 23, 2024 13:37
@leonid-shevtsov
Copy link
Contributor Author

Done @grosser.

@grosser grosser merged commit b69c82b into premailer:master Aug 23, 2024
6 checks passed
@grosser
Copy link
Contributor

grosser commented Aug 23, 2024

1.19.0

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