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:
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...
allow the use of a path-to-class dict (O(1)) instead of constant rege…
…x searching (O(n))
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.
@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)
prevent bad ThreadDict things - why does this assume ThreadDict is in…