惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
B
Blog
Last Week in AI
Last Week in AI
Jina AI
Jina AI
WordPress大学
WordPress大学
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
宝玉的分享
宝玉的分享
T
Tailwind CSS Blog
P
Proofpoint News Feed
酷 壳 – CoolShell
酷 壳 – CoolShell
Google DeepMind News
Google DeepMind News
U
Unit 42
雷峰网
雷峰网
J
Java Code Geeks
Apple Machine Learning Research
Apple Machine Learning Research
MongoDB | Blog
MongoDB | Blog
F
Fortinet All Blogs
美团技术团队
Y
Y Combinator Blog
腾讯CDC
B
Blog RSS Feed
T
The Blog of Author Tim Ferriss
Microsoft Azure Blog
Microsoft Azure Blog
Recent Announcements
Recent Announcements

The Rust Programming Language Forum - Latest posts

What's everyone working on this week (21/2026)? Rust Function Call with one Param Iced + Canvas + Text: How do I create a style for canvas text "Value dropped while borrowed" as a lifetime mismatch Weird `use of moved value` behaviour Slightly surprising behavior of a while loop Clap: how to disable options after a certain positional argument How do i tell rust-analyzer what kind of bracket to use for a macro? Iterator + Borrow Checker: Work around borrowing already borrowed mutable variable Requesting data via mavlink SKILLS.md for Rust development 🧵 Stringlet UTF-8 Hack Option Niche? Iterator + Map - How do divide every element, including the last element, by the last element Why can't we store returned value of a function in a variable if one of the parameters goes out of scope My first crate :D, floop: A more convenient and less error prone replacement for loop `{ select! { .. }}` Sorting is slow because architectures are wrong — zan-sort redesigns the architecture, not the algorithm Iced Font - Create a custom monospace font to display dollar amounts Is the UnsafePinned RFC wrong about being able to return `&mut T` from `get_mut_unchecked`? Fixing Polars 0.37 compilation errors: Hashbrown 0.17 dependency conflict and decimal parsing Any plans for improving error diagnostic in Rust 2.0? How do I build completely offline? Is `&mut T -> &mut ManuallyDrop<T>` well-defined and sound? Would you use this? — fixtura, declarative fake data injection for tests Foreign trait restrictions on native types make generics hard to use Cargo Exclude Directive Compiler reasoning around a modulo counter Multiple mutable references to elements within one vector Handling non-`Send` data in a `Send` closure Review: Static Multi Pool Allocator Rmquickjs - High-level MicroQuickJS bindings for Rust
CSV to SQLite - Is it better to write records as they are...
eechris · 2026-04-19 · via The Rust Programming Language Forum - Latest posts

April 18, 2026, 9:15pm 1

I have a rust program that reads a CSV file (approx 3000 rows with 5 pieces of data / row) and inserts it into an SQLite database. Currently I have one function that reads the CSV into a vector of structures and a second function that takes the vector and writes it to an SQLite database. It works. Does it make more sense to write the data to the SQL database as it is being read from the CSV file i.e. record by record, eliminating the need to create a large vector of structures?

mroth April 18, 2026, 9:34pm 2

It depends. It depends on your requirements. Only the requirements.

So ask yourself a few questions:

  • How large will the typical CSV file be?
  • Under realistic assumptions, how large could the largest CSV file be?
  • Will you always process files, or do you also need to read from a stream?
  • What are the memory constraints of the machine your tool runs on?
  • What are the processing constraints of the machine your tool runs on?
  • And so on.

Most importantly: what do you need now?

In this context, “now” could mean this week, this month, or this year. It depends on the environment your program runs in.

kpreid April 18, 2026, 9:39pm 3

There are various factors which can affect whether one or the other is more efficient, and it's difficult to say without taking measurements.

Ways writing all the records at once can be more efficient:

  • The CPU does not have to switch between executing code to read CSVs and executing code to write SQLite, potentially making better use of both instruction cache and data cache.
  • SQLite may be more efficient at writing multiple records in a single transaction. (I don't know if this is true).

Ways writing the records one at a time can be more efficient:

  • Whenever an item is added to a vector exceeding its capacity, the vector has to grow — copying the data into a new memory allocation. If you write the records one at a time, you don't need to do this copying.
  • The process takes less memory overall, so the operating system does not have to displace other potential uses of the memory (e.g. disk cache or other processes’ memory).

A frequently useful compromise between these modes of operation is to pick a number of records to be your buffer size, and read only up to that many records before switching to writing. However, before considering complicating things this way, you should measure the performance of both of the basic strategies, on large files and small files.

1 Like

mroth April 18, 2026, 9:48pm 4

It is true. Depending on whether Write-Ahead Logging is enabled, the difference can be enormous.