Memory spike with zeroblob
Hello, I have this sample python code that I run under x64 3.8.6 on Windows import sqlite3 file = "BLABLABLABLBLA_sql.bak" db = sqlite3.connect('generic.bckp') cursor = db.cursor() cursor.execute('CREATE TABLE t (id INTEGER PRIMARY KEY, b BLOB, p BLOB)') cursor.execute('INSERT INTO t VALUES(?, zeroblob(?), ?)', [1, 100256716, file.encode()]) Problem is the memory profiler says it allocates about 200 Mb of memory If I remove either the zeroblob or the binary encoded file name - all is well Momchil Bozhinov (posting anonymously due to being lazy)
SQLite tries to optimize memory usage by not allocating zero bytes that occur at the end of a record. So a zeroblob() at the end of a record does not require a memory allocation. However, you have a few additional non-zero bytes that follow your big zeroblob, and so SQLite is compelled to allocate space for the entire thing.
Much less memory would be required if you exchange the order of the b and p columns.
Thank you for this. It did help So keep the huge blob at the end of it. Got it. Would have been nice to get some sort of a notice or at least note somewhere in the zeroblob docs I use apsw so that was my first stop, then the python sqlite implementation before I ended up here