Skip to content

Improve performance of http.cookiejar.join_header_words #128982

Open
@picnixz

Description

Feature or enhancement

Proposal:

Currently, we use if not re.search(r"^\w+$", v):. This can be replaced by if not v.isalnum() and '_' not in v. Benchmarks are as follows:

$ ./python -m pyperf timeit -s 'x = [[("text/plain", None), ("charset", "iso-8859-1\"")]]; from http.cookiejar import join_header_words as f' 'f(x)'
Mean +- std dev: [ref] 795 ns +- 8 ns -> [new] 604 ns +- 20 ns: 1.32x faster

It doesn't help having a compiled regex by the way.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

Metadata

Assignees

Labels

performancePerformance or resource usagestdlibPython modules in the Lib dirtype-featureA feature request or enhancement

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions