Opened 8 years ago

Closed 8 years ago

#6965 closed (fixed)

urlize should be faster

Reported by: floguy Owned by: Salkot
Component: Template system Version: master
Severity: Keywords:
Cc: floguy@…, andrew@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Running the urlize or urlizetrunc filter on some text that is very large, or running it many times seems to slow down the system more than it should.

Attachments (2)

faster_urlize.diff (4.9 KB) - added by floguy 8 years ago.
Improved speed to about 50x faster. Tests still pass.
faster_urlize_r7936_t6965.diff (1.3 KB) - added by Salkot 8 years ago.
Makes urlize faster

Download all attachments as: .zip

Change History (14)

comment:1 Changed 8 years ago by mrts

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

I'd be +1 on no email-to-mailto by default and adding an extra filter urlize_with_emails that supports email-to-mailto.

comment:2 Changed 8 years ago by floguy

Cc: floguy@… added
Has patch: set
Owner: changed from nobody to floguy
Status: newassigned

Changed 8 years ago by floguy

Attachment: faster_urlize.diff added

Improved speed to about 50x faster. Tests still pass.

comment:3 Changed 8 years ago by Chris Beaven

From a quick skim of your code, it seems like you're changing how the escaping works - what if a URL has an ampersand in it? Potentially couldn't you break the HTML if it trimmed to a limit half way in an &?

comment:4 Changed 8 years ago by floguy

Patch needs improvement: set

Great point! I'm going to have to think about how to overcome that, since it'll probably foil this whole current scheme.

comment:5 Changed 8 years ago by dnaquin@…

floguy, are you still working on this? Otherise, I can take a stab at it.

comment:6 Changed 8 years ago by floguy

No, go ahead. I implemented it another way but it made the code almost as slow as the old version :-(

comment:7 Changed 8 years ago by devin

Owner: changed from floguy to devin
Status: assignednew

comment:8 Changed 8 years ago by devin

Owner: devin deleted

I gave my shot at this these last couple days, but the overhead seems to largely be in the regular expressions. punctuation_re especially seems clunky. I, however, don't know enough about regular expressions to optimize them.

comment:9 Changed 8 years ago by Salkot

Owner: set to Salkot
Status: newassigned

Changed 8 years ago by Salkot

Makes urlize faster

comment:10 Changed 8 years ago by Salkot

Cc: andrew@… added
Component: UncategorizedTemplate system
Patch needs improvement: unset

I created a patch that skips the regex match for most words. This resulted in 10x speed improvement on a test set of real posts. The reason for checking for '@' and ':' on line 98 is because I don't want to change the behavior for e.g. http://localhost/ even though it's not clear whether this should be supported or not (I don't think so). The len call was removed for good measure.

comment:11 Changed 8 years ago by Chris Beaven

Triage Stage: UnreviewedReady for checkin

Patch looks good. Existing tests will be enough so I it's ready to rock.

comment:12 Changed 8 years ago by Malcolm Tredinnick

Resolution: fixed
Status: assignedclosed

(In [7985]) Fixed #6965 -- Sped up the urlize and urlizetrunc filters. A nice patch from Andrew Badr.

Note: See TracTickets for help on using tickets.
Back to Top