FAQ  •  Register  •  Login

Plugin Performance Surprise

<<

jhb50

DLNA master

Posts: 2843

Joined: Thu Jun 30, 2011 9:32 pm

Post Tue Nov 13, 2012 5:32 am

Plugin Performance Surprise

I was wondering why one of my plugins was taking so long to refresh so by adding log messages to each step of the code I timed it and found.

Due to this regex
(?s).*?'file'.*?'(.*?)'
Extracts took 5 sec each

Now with this regex
(?s)'file'.*?'(.*?)'
Extracts take 1 sec each!

Can you believe it?
Can you explain it?
<<

zip

User avatar

Serviio developer / Site Admin

Posts: 17212

Joined: Sat Oct 24, 2009 12:24 pm

Location: London, UK

Post Tue Nov 13, 2012 9:47 am

Re: Plugin Performance Surprise

the regex is different, so that's why ;-)
<<

jhb50

DLNA master

Posts: 2843

Joined: Thu Jun 30, 2011 9:32 pm

Post Tue Nov 13, 2012 4:37 pm

Re: Plugin Performance Surprise

So you don't understand regex either? :shock:
Kinda important when the big issue with Serviio is the time required to constantly refresh all the online feeds even if they are not being used.
<<

zip

User avatar

Serviio developer / Site Admin

Posts: 17212

Joined: Sat Oct 24, 2009 12:24 pm

Location: London, UK

Post Tue Nov 13, 2012 4:59 pm

Re: Plugin Performance Surprise

It's called lazy quantifiers. http://www.asiteaboutnothing.net/regex/regex-greed.html

I'm not sure how it's implemented in Groovy/Java, but it looks like it's slower than greedy expression. Use it only if you need it.
<<

jhb50

DLNA master

Posts: 2843

Joined: Thu Jun 30, 2011 9:32 pm

Post Wed Nov 14, 2012 3:09 am

Re: Plugin Performance Surprise

My conclusion is opposite to yours, and lazy will stop as soon as it gets a match whereas greedy will continue and then backtrack.

I'm only using lazy so it should be fast and I read (?s).*?'file'.*?'(.*?)' as read the html string up to 'file' and then up to the next ' and then capture to the next quote and stop. However I read (?s)'file'.*?'(.*?)' the same way but it takes 5 times longer so something is different.
<<

miksa

Serviio lover

Posts: 68

Joined: Fri Nov 09, 2012 2:30 am

Post Thu Nov 15, 2012 2:09 am

Re: Plugin Performance Surprise

jhb50 wrote:Due to this regex
(?s).*?'file'.*?'(.*?)'
Extracts took 5 sec each

Now with this regex
(?s)'file'.*?'(.*?)'
Extracts take 1 sec each!
i can see that first regex has 4 pattens and second only 3. that might explain difference in performance. i guess execution of each pattern takes extra time.
- Mike

Return to Plugin development

Who is online

Users browsing this forum: No registered users and 12 guests

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.