New GitHub issue #110643 from kfdf:<br>

<hr>

<pre>
The row factory example that returns a namedtuple in [the sqlite docs](https://docs.python.org/3/library/sqlite3.html#how-to-create-and-use-row-factories) creates a new namedtuple class for every instance and as a result is really, really slow. A couple of orders of magnitude slower is too much even for an example, people might still use it and assume that one class per row doesn't affect performance that much. Introducing caching makes the example a bit less concise, but at least it becomes usable.

```
from collections import namedtuple
from functools import lru_cache

@lru_cache
def make_row_class(description):
    return namedtuple('Row', (col[0] for col in description))

def named_tuple_factory(cursor, row):
    return make_row_class(cursor.description)(*row)
```

</pre>

<hr>

<a href="https://github.com/python/cpython/issues/110643">View on GitHub</a>
<p>Labels: docs</p>
<p>Assignee: </p>