I have used sqlite to insert millions of rows at runtime and this is what I have used to increase performance:
- Use as few transactions as possible.
- Use parametrized commands for
inserting the data (prepare the
command once and just change
paramater values in the loop)
- Set
PRAGMA synchronous OFF (not sure
how it works with WAL)
- Increase page size of the database.
- Increase cache size. This is an important setting as it will cause sqlite to actually write the data to the disk fewer times and will run more operations in memory making the whole process faster.
- If you need an index add it after inserting the rows by running the necessary sqlite command. In this case you will need to ensure uniqueness yourself as you are currently doing it now.
If you try these please post your test results. I believe it will be interesting for everyone.