E531 Encoding: better regex performance by matej21 · Pull Request #36 · nette/neon · GitHub
[go: up one dir, main page]

Skip to content

Encoding: better regex performance#36

Closed
matej21 wants to merge 1 commit intonette:masterfrom
matej21:encode_performance
Closed

Encoding: better regex performance#36
matej21 wants to merge 1 commit intonette:masterfrom
matej21:encode_performance

Conversation

@matej21
Copy link
Contributor
@matej21 matej21 commented Jan 2, 2017

see matej21/neon-js#3

This regex may become very slow in a combination with end of string assertion

see this and this and compare number of steps (it increases exponentially)

Performance test:

$encoder = new \Nette\Neon\Encoder();
$var = str_repeat('a', 20) . ',';

$start = microtime(TRUE);
for ($i = 0; $i < 1000; $i++) {
	$encoder->encode($var);
}
echo microtime(TRUE) - $start;
echo "\n";

before: 3.8s
now: 0.005s

thanks @JirkaVebr for a help

@dg
Copy link
Member
dg commented Jan 2, 2017

https://regex101.com is awesome! Where it was my whole life?

@dg dg closed this in 3a2f839 Jan 2, 2017
@dg
Copy link
Member
dg commented Jan 2, 2017

I hope this fix will work 3a2f839

dg added a commit that referenced this pull request Jan 2, 2017
dg added a commit that referenced this pull request Jan 4, 2017
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

0