Woundorf / foxreplace

Replace text in webpages
https://addons.mozilla.org/firefox/addon/foxreplace/
GNU General Public License v3.0
90 stars 22 forks source link

firefox stops extension on bigger pages when multiple regex are used #257

Open ssbarnea opened 6 years ago

ssbarnea commented 6 years ago

Please try to load a log file like the one at https://logs.rdoproject.org/38/610038/3/openstack-check/tripleo-ci-centos-7-ovb-3ctlr_1comp-featureset001-pike-branch/d5bd381/logs/undercloud//home/zuul/.instack/install-undercloud.log.txt.gz

And use configuration from https://raw.githubusercontent.com/openstack/coats/master/coats/FoxReplace.json

This will make Firefox stop the extension even on highend machines (8 cores/48GB RAM).

What can we do to make it still usable? Any guidelines for improving performance for such use-cases?

Woundorf commented 6 years ago

I have made some tests and the most expensive are the regexps that have .* at the beginning: if I remove the three substitutions that have this and keep the rest the substitutions are instantaneous. Thus it looks like evaluating .* at the beginning of a regexp is orders of magnitude more expensive than at the end for example.

Then I have made another test: adding ^ at the beginning of those three substitutions (i.e. in one of them setting the regexp as ^(.* failed with error code .*)), so that they match from the beginning, which I think is the same behaviour that you intended; with this it's also instantaneous, so this could be a solution.

Tell me if this works for you.

Also, I see that all the substitutions in the "failed2" group are enclosed in parentheses and then $1 is used in the output. In these cases you could remove the parentheses and use $& in the output to get the same result (just like it's done in the other group). I don't know if this can make any difference in performance.

Related to #126 and #130.

ssbarnea commented 6 years ago

Thanks! Following your recommandation clearly sorted the not-responding issue. I also consolidated few different regexes as I suppose that their number also influence the speed.