Skip to content

Increase performance up to 15000% #98

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

Merged
merged 4 commits into from
Feb 11, 2016

Conversation

ossinkine
Copy link
Contributor

The basic idea is to use an array of characters instead of string processing.

Benchmark
For test I took the current css-file from github.com: https://assets-cdn.github.com/assets/github-a15e59d993eb0844d736a04652f63d465d909127e84cf7cd27073076df530f05.css

$source = file_get_contents('https://assets-cdn.github.com/assets/github-a15e59d993eb0844d736a04652f63d465d909127e84cf7cd27073076df530f05.css');
$time = microtime(true);
$parser = new Sabberworm\CSS\Parser($source);
$css = $parser->parse();
var_dump(microtime(true) - $time);

On the my machine I received the following results:
before float(180.93577218056)
after float(1.1720938682556)

@sabberworm
Copy link
Collaborator

Why 150000000% while you’re at it…

Just kidding. Great work, thanks a lot!

@@ -56,7 +59,7 @@ public function __construct($sText, Settings $oParserSettings = null) {

public function setCharset($sCharset) {
$this->sCharset = $sCharset;
$this->iLength = $this->strlen($this->sText);
$this->iLength = count($this->aText);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see a problem here: splitting should only happen after the charset is known (because it depends on the charset used).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, the @charset declaration will call this method during parsing. But it should trigger a re-parse if the count is different in the new charset. Which it has never done. So, again, this is due for a rework that hasn’t necessarily got anything to do with your changeset.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If it so, why is bMultibyteSupport flag needed? Can I pass bMultibyteSupport = false and @charset "UTF-8"?

sabberworm added a commit that referenced this pull request Feb 11, 2016
Increase performance up to 15000%
@sabberworm sabberworm merged commit 3f4c774 into MyIntervals:master Feb 11, 2016
@ossinkine ossinkine mentioned this pull request Feb 11, 2016
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