Swap ownership, fsync race, RowsView memory, renderer regex stack
- A session never unlinks a journal it does not own: Detach, ResetJournal and NotifyFilenameChanged skip removal when this session was locked out or another session holds the lock, and PruneSwapDir skips held journals. A second session used to delete the first session's live journal on save or close. - The writer thread's periodic fsync now runs under mtx_. It fsynced fds that the main thread could close concurrently (or that had been reused); an in-flight fsync also kept a just-closed journal's flock alive, so the owner's own cleanup saw its journal as held. - Compaction locks the compacted file before renaming it into place and keeps using it, so the journal is never unlocked in between; a failed lock on the truncating reopen marks the session locked out. - Unnamed-buffer journals include the pid, so sessions no longer share (and delete) each other's unnamed-N.swp. - RowsView keeps only the previous generation of cached rows: keeping all of them made C-u 2000 M-d on a 1 MiB line use ~2 GB. - Renderers run regex match highlighting through ForEachRegexMatch, which uses the large-stack worker for lines over 512 bytes; some patterns overflowed the main stack well under the previous 10,000 byte limit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015rcVQiiWyTzoNrsvLSaAfB
This commit is contained in:
+7
-6
@@ -457,9 +457,11 @@ compute_mark_region(Buffer &buf, std::size_t &sx, std::size_t &sy, std::size_t &
|
||||
// Row access for commands that touch a few rows. Buffer::Rows() rebuilds a
|
||||
// string for every line of the file on the first call after any edit, which
|
||||
// made every motion and delete O(file size). RowsView fetches rows on demand
|
||||
// and caches them for the current buffer version. Strings fetched for an
|
||||
// older version are retired, not freed, so a reference obtained before an
|
||||
// edit stays valid (if stale) for the lifetime of the view, as with Rows().
|
||||
// and caches them for the current buffer version. When the version changes
|
||||
// the current cache becomes the previous one (the one before that is freed),
|
||||
// so a reference obtained just before an edit stays valid (if stale) across
|
||||
// that edit. Keeping every generation grew without bound in loops that edit
|
||||
// on each pass (C-u 2000 M-d on a long line used ~2 GB).
|
||||
class RowsView {
|
||||
public:
|
||||
explicit RowsView(const Buffer &buf) : buf_(&buf) {}
|
||||
@@ -480,8 +482,7 @@ public:
|
||||
const std::string &operator[](std::size_t row) const
|
||||
{
|
||||
if (buf_->Version() != version_) {
|
||||
if (!cache_.empty())
|
||||
retired_.push_back(std::move(cache_));
|
||||
previous_ = std::move(cache_);
|
||||
cache_.clear();
|
||||
version_ = buf_->Version();
|
||||
}
|
||||
@@ -495,7 +496,7 @@ private:
|
||||
const Buffer *buf_;
|
||||
mutable std::uint64_t version_ = ~std::uint64_t{0};
|
||||
mutable std::map<std::size_t, std::string> cache_;
|
||||
mutable std::vector<std::map<std::size_t, std::string> > retired_;
|
||||
mutable std::map<std::size_t, std::string> previous_;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user