# Improvement on current \`difflib.SequenceMatcher\` algorithm

**URL:** <https://discuss.python.org/t/improvement-on-current-difflib-sequencematcher-algorithm/106221>\
**Category:** Ideas\
**Created:** [February 19, 2026, 10:26pm UTC](https://discuss.python.org/t/improvement-on-current-difflib-sequencematcher-algorithm/106221 "2026-02-19T22:26:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dg-pb](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/dg-pb/32/16248_2.png) [@dg-pb](https://discuss.python.org/u/dg-pb)\
**Post date:** [February 19, 2026, 10:26pm UTC](https://discuss.python.org/t/improvement-on-current-difflib-sequencematcher-algorithm/106221/1 "2026-02-19T22:26:37Z")

</div>

Took a step back from implementing new Matcher with Automaton and did some work to improve the current one.

- Find document [here](https://gistcdn.githack.com/dg-pb/09c159f726ed507ac28afedac8f168ad/raw/288fba13f3ef20f277561566b1050f945ea28caf/str_alg_lcstr_dict_multilayer.html)
- And the code [here](https://gist.github.com/dg-pb/4e08bc770a3b52d3ec77af3e38fdbb20)

For the worst case with `autojunk=True` (which this improvement is targeted at):

| | difflib’s current | new algorithm |
| --- | --- | --- |
| size 10K | 10.6 s | 0.2 s |
| size 15K | 24.1 s | 0.4 s |
| size 20K | 60.5 s | 0.8 s |
| size 50K | ~ 13 m | 6.6 s |
| size 100K | ~ 1.5 h | 31 s |

- Memory increase is reasonable.
- Additional complexity is average.

* * *

As the default `Matcher` isn’t changing, maybe the improvement is worth it?

I think it might pay off in the long run - it would solve 99% of related issues.
