Recorded Nov 20, 2026 on pallets/markupsafe · Python · 869 commits of history

Why does Markup.striptags collect the text between tags into a list in a single pass, instead of removing tags from the string one at a time?

Answered44sgemini-3.5-flash

Evidence by depth35 finds · 8 relevant · 4 cited

  1. Code now

  2. Commits · what changed

  3. Pull requests · the goal

  4. Issues · the need

Markup.striptags collects text into a list in a single pass to fix a performance regression caused by quadratic string manipulation F-32. This approach ensures the function scales linearly with input size, whereas previous incremental removal methods were significantly slower on large inputs F-35 F-32.

What changed

The implementation was updated to use a single while loop that scans for tags using str.find, appends the text between tags to a list named parts, and joins them once at the end F-07 F-32. This replaced a "naive" refactor that had attempted to remove regular expressions by incrementally removing blocks, which resulted in quadratic complexity F-31 F-32.

Why

The change was motivated by benchmarks showing that the previous incremental approach was up to 1000x slower than the original regex-based version for large inputs F-35. While the maintainers wanted to avoid regex due to its own performance issues and deep call stacks, the initial replacement was inefficient because it performed repeated string manipulations F-32 F-35. The single-pass list-collection method matches the style used for other scanners in Werkzeug to provide better performance without using regex F-32.

High confidence

4 sources cited · 2 hops · 8 LLM calls · 26,611 tokens · 44s

How this answer was found
  1. 0:03

    Plan

    A why question about Markup.striptags.

    • codedef striptags
    • commitsstriptags single pass performance
    • pull requestsstriptags implementation list join
    • docsMarkup.striptags method details
  2. 0:03

    Search docs

    6 found · markup.striptags method details

  3. 0:03

    Search code

    6 found · def striptags

  4. 0:03

    Search commits

    6 found · striptags single pass performance

  5. 0:04

    Search pull requests

    Nothing found · striptags implementation list join

  6. 0:05

    Trace history

    src/markupsafe/__init__.py L199-238 (Markup.striptags) -> 6 commits (commit:df5d581, commit:f38ca06, commit:872a117, commit:0b6bee0, commit:e1b2934, commit:084c62a); tests/test_markupsafe.py L77-89 (test_escaping) -> 6 commits (commit:dcb1…

  7. 0:09

    Grade evidence

    5 kept as relevant; following #413, #522, #496, #437

  8. 0:11

    Grade evidence

    7 kept as relevant; following #521

  9. 0:12

    Grade evidence

    8 kept as relevant

  10. 0:18

    Draft answer

    High confidence, 4 citations

  11. 0:43

    Check claims

    8 claims checked, all supported

  12. 0:43

    Done

    4 citations, 8 evidence items, 2 hops

17/17 events