Skip to content

New CSS parser with go-css-lexer - #415

Merged
NGTmeaty merged 8 commits into
mainfrom
new-css-parser
Aug 6, 2025
Merged

NGTmeaty merged 8 commits into
mainfrom
new-css-parser

Conversation

@yzqzss

@yzqzss yzqzss commented Aug 5, 2025

Copy link
Copy Markdown
Collaborator

https://github.com/renbaoshuo/go-css-lexer

This is a brand new CSS lexer, which complies with the latest CSS syntax.

The go-css-lexer can handle nested CSS, so in this PR I removed the previous regex fallback parser as well.

cc: @renbaoshuo


ref: #345 (comment)

@yzqzss yzqzss self-assigned this Aug 5, 2025
@codecov-commenter

codecov-commenter commented Aug 5, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.75904% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 55.50%. Comparing base (66dd982) to head (03874f1).
⚠️ Report is 119 commits behind head on main.

Files with missing lines Patch % Lines
internal/pkg/postprocessor/extractor/css.go 92.02% 9 Missing and 2 partials ⚠️
internal/pkg/postprocessor/extractor/css_util.go 78.57% 4 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #415      +/-   ##
==========================================
+ Coverage   55.21%   55.50%   +0.28%     
==========================================
  Files         118      119       +1     
  Lines        7282     7302      +20     
==========================================
+ Hits         4021     4053      +32     
+ Misses       2940     2926      -14     
- Partials      321      323       +2     
Flag Coverage Δ
e2etests 37.41% <0.00%> (-0.11%) ⬇️
unittests 31.86% <89.75%> (+0.59%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@yzqzss
yzqzss requested a review from NGTmeaty August 5, 2025 23:26
NGTmeaty
NGTmeaty previously approved these changes Aug 5, 2025

@NGTmeaty NGTmeaty left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks great! I'm mostly just curious - but have you ran benchmarks on the old library vs the new one?

@yzqzss
yzqzss marked this pull request as draft August 6, 2025 04:44
@yzqzss

yzqzss commented Aug 6, 2025

Copy link
Copy Markdown
Collaborator Author
ExtractFromURLCSS():

old BenchmarkCSS                  494554 ns/op            144378 kB/s   305616 B/op       1702 allocs/op
old_regex BenchmarkCSS            475908 ns/op            150005 kB/s   305613 B/op       1702 allocs/op
csslexer v0.0.2 BenchmarkCSS      931164 ns/op             76681 kB/s   820866 B/op      15560 allocs/op
csslexer v0.0.3 BenchmarkCSS      538515 ns/op            132580 kB/s   447160 B/op         49 allocs/op

I just optimized the go-css-lexer (v0.0.3) and now it's fast enough with minimum memory allocation footprint. renbaoshuo/go-css-lexer#1

@yzqzss
yzqzss marked this pull request as ready for review August 6, 2025 05:56

@NGTmeaty NGTmeaty left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the improvements there! That's great!

@NGTmeaty
NGTmeaty merged commit f160c5b into main Aug 6, 2025
5 checks passed
@yzqzss
yzqzss deleted the new-css-parser branch August 6, 2025 22:12
@yzqzss yzqzss added the GSoC label Aug 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants