Skip to content

allow the optional use of a path-to-class dict instead of regex-matching all paths, workaround Issue #214 and general perf improvement #215

Open
wants to merge 2 commits into from

2 participants

@daubman
daubman commented Mar 12, 2013

If you have a constant (no regex matching necessary) set of paths to map, you can now add use_path_dict=True to your:
app = web.application(urls, globals(), use_path_dict=True)
call to use a dict of something like:
{'web.ctx.path-1': class_to_handle_path-1}

rather than avoiding the regex matching against all paths for every call.

While this will have a tiny perf boost, its main benefit is avoiding the non-thread-safe memoization of re_compile discussed in Issue #214

This should be completely transparent and backwards compatible for any users requiring regex matching of paths...

@anandology

This is not related to re.compile issue at all. The re.compile issue needs to be fixed, but I don't think this work-around for handling just a rare special case is worth it.

@daubman
daubman commented Mar 13, 2013

@anandology Some followup questions / comments:

1) IMHO, this is directly related to the re.compile issue - it does not FIX that issue, but provides a workaround for the most highly-threaded use of re.compile that is currently causing us to throw ~200 500 Errors an hour in production.

2) Can you qualify "rare special case"? I would think this functionality would be highly desirable for any site that uses params rather than paths, and so would never ever need the cost of regex matching a potentially long list of paths (memoization or not) - if you ever look at a CProfile of web.py calls for a site with many paths, it gets pretty crazy as all those regexes are tested... Is there data that suggests that almost every site using web.py actually uses/needs the regex matching?

3) Can you qualify "worth it"? IMHO, the cost of this patch is zero to anybody not interested in using it... (and in total involves <15 LOC changes)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.