News for hackers. Stuff that matters.
Re:Inserting 100k rows 66 times faster by throwaway143829 on Wednesday March 20, 2024 @08:27AM (#39765486)
TLDR to get better performance, use bulk inserts instead of inserting one row per query. And (unrelated to DB perf) don't use the spread operator in JS for passing function args (the author says not to use the spread operator at all but you don't need to go that far)
Re:Inserting 100k rows 66 times faster by ak39 on Wednesday March 20, 2024 @08:31AM (#39765508)
Thank you. Also, what database was in use?
Re:Inserting 100k rows 66 times faster by throwaway143829 on Wednesday March 20, 2024 @08:31AM (#39765516)
sqlite3, but I think bulk inserts would improve perf for other DBs too.
Re:Inserting 100k rows 66 times faster by kikimora on Wednesday March 20, 2024 @09:14AM (#39765982)
PG has “copy” which would blow away bulk inserts. Other DB vendors have similar stuff for high-performance inserts. You would be much better off using those than using bulk inserts.
Re:Inserting 100k rows 66 times faster by vbezhenar on Wednesday March 20, 2024 @08:32AM (#39765529)
JDBC has "batch updates" feature. You can use single inserts but they're sent as a batch of multiple statements to the database. Not sure about JS libraries, but this feature also significantly improves performance and probably easier to use and maintain.

For super fast inserts you can use postgres COPY feature. But it has to be implemented in the driver.

Re:Inserting 100k rows 66 times faster by NathanaelRea on Wednesday March 20, 2024 @08:43AM (#39765645)
I wonder how `.import` would compare vs creating a huge batch insert string in memory.
Re:Inserting 100k rows 66 times faster by kikimora on Wednesday March 20, 2024 @09:12AM (#39765961)
I remember SQLite have been using inserts to implement import under the hood.
Re:Inserting 100k rows 66 times faster by lmz on Wednesday March 20, 2024 @09:17AM (#39766005)
I wonder if they tried prepared statements - parsing 100k identical insert statements surely is avoidable.
Re:Inserting 100k rows 66 times faster by xnacly on Wednesday March 20, 2024 @10:05AM (#39766732)
I didn’t even think of that, I‘m gonna have to try them out and compare against the two other implementations.
Re:Inserting 100k rows 66 times faster by avinassh on Wednesday March 20, 2024 @11:04AM (#39767635)
you might like my post - Towards Inserting One Billion Rows in SQLite Under A Minute [0]

[0] - https://avi.im/blag/2021/fast-sqlite-inserts/