CSS file of 320 bytes takes 10+ seconds to parse
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 42/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- python
- 領域
- performance
調査の方向性
リンクされた再現可能な例から始め、cssutils/parse.py、cssutils/css/cssstylesheet.py、util.py、tokenize2.py を通る報告されたパスを追跡します。改行とスタイル式を変化させながらサンプルのベンチマークを実行し、入力のパース時間が指数関数的にならなくなったことを示す回帰テストを追加します。
索引モデルが issue の本文から書いたものです。
説明
I've encountered CSS file which cssutils library takes lots of seconds to parse (in fact, almost infinite).
After some investigation I've minified problematic sample (as possible) and prepared reproducible code example.
On my laptop (core i7-8550U) it takes 14 seconds to parse file with just one line and 320 bytes of text.
Original file has 20kBytes of text and parser does not finish it in several hours.
Code:
https://gist.github.com/vdmit/ef9007170fa1c616cf5aba1fcebfce87
I'm using:
- latest stable
cssutilsrelease 2.3.0 from pypi repo - python 3.8.10
- Ubuntu 20.04 linux distribution.
Notes:
- original CSS file was malformed and even contained non-printable characters. My minified example is still not valid CSS file, but it is a plain ANSI file.
- Adding line break in any place fixes problem;
- Removing of last style expression (
.s11...reduces execution time from 14 seconds to 3 seconds). - Adding of one more style expression increases execution time from 14 seconds to 50, 2 more styles yields ~260 seconds.
So, there is a exponential complexity somewhere, which is strange.
Traceback of interrupted script is following:
Traceback (most recent call last):
File "cssutils_infinite_loop_bug_example.py", line 10, in <module>
sheet = css_parser.parseString(cssText=css_text)
File "/home/vdmit/.local/lib/python3.8/site-packages/cssutils/parse.py", line 147, in parseString
sheet._setCssTextWithEncodingOverride(
File "/home/vdmit/.local/lib/python3.8/site-packages/cssutils/css/cssstylesheet.py", line 408, in _setCssTextWithEncodingOverride
self.cssText = cssText
File "/home/vdmit/.local/lib/python3.8/site-packages/cssutils/css/cssstylesheet.py", line 331, in _setCssText
wellformed, expected = self._parse(
File "/home/vdmit/.local/lib/python3.8/site-packages/cssutils/util.py", line 484, in _parse
expected = p(expected, seq, token, tokenizer)
File "/home/vdmit/.local/lib/python3.8/site-packages/cssutils/css/cssstylesheet.py", line 313, in ruleset
rule.cssText = self._tokensupto2(tokenizer, token)
File "/home/vdmit/.local/lib/python3.8/site-packages/cssutils/util.py", line 343, in _tokensupto2
for token in tokenizer:
File "/home/vdmit/.local/lib/python3.8/site-packages/cssutils/tokenize2.py", line 172, in tokenize
match = matcher(text, pos) # if no match try next production
KeyboardInterrupt
- 主要言語
- Python
- スター
- 92
- フォーク
- 30
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
jaraco/cssutils のほかの issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
-
help wanted
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
-
Wrong specificity オープンhelp wanted
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
-
enhancement help wanted
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
jaraco/cssutils の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
anthropics/skills#1811 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
speaches-ai/speaches#678 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
datalayer/mcp-compose#42 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
conda-forge/spacy-feedstock#177 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
UKGovernmentBEIS/inspect_evals#2523 ·