-
Notifications
You must be signed in to change notification settings - Fork 5.6k
perf: disable WAL for transpiled source cache #18084
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Deno always passes along a hash of the source text it's loaded and won't use the cache unless it matches, so I don't think that will be an issue. |
cli/cache/common.rs
Outdated
-- enable write-ahead-logging mode | ||
PRAGMA journal_mode=WAL; | ||
-- Disable write-ahead-logging mode | ||
PRAGMA journal_mode=Off; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it faster when the SQLite file is large?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unclear, I think it has more impact on highly concurrent usage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering because of this:
The traditional rollback journal works by writing a copy of the original unchanged database content into a separate rollback journal file and then writing changes directly into the database file. In the event of a crash or ROLLBACK, the original content contained in the rollback journal is played back into the database file to revert the database file to its original state. The COMMIT occurs when the rollback journal is deleted.
The WAL approach inverts this. The original content is preserved in the database file and the changes are appended into a separate WAL file. A COMMIT occurs when a special record indicating a commit is appended to the WAL. Thus a COMMIT can happen without ever writing to the original database, which allows readers to continue operating from the original unaltered database while changes are simultaneously being committed into the WAL. Multiple transactions can be appended to the end of a single WAL file.
Can we lazy initialize sqlite instead? Why do we need to open a sqlite file always |
@littledivy it helps with a major performance improvement to startup time which caches the swc dependency analysis for deno_graph #15502 -- maybe there is a better way than sqlite |
20d18db
to
ad69226
Compare
I've combined executing pragmas and setting up tables into a single batch query. It seems to make SQLite show up on flamegraphs as 1.6% compared to 2.5%. |
Can you update with how many records were in your sqlite database? It might be good to test this by inserting synthetic data into the database as well then testing at different sizes. |
I cherry-picked these on top of 7cf6e2a 7cf6e2a -- base e92d5d2196fdcb889641b476a54f2b1fea82f8d3 -- PR w/cherry-pick There's at least ~.3ms speedup here with a trivial script (~8kB, no imports).
|
@mmastrac could you create a fake DB with 1000/10000 entries to see if there's still an improvement? |
I have a couple of small concerns here:
I'm building a test database to investigate further. |
The benchmarks with a large database are virtually the same (benchmark order reversed to maintain the WAL for the test):
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this PR is correct. We may truncate some older cache WAL logs but I don't believe this is harmful long-term. I think there's a slightly higher chance of database corruption but I put together a PR to ensure that we don't silently fail and the user isn't confused:
https://github.com/denoland/deno/pull/18330/files
In the future we may want to investigate one of the alternate journaling modes, but I think this is good for now.
Disable Write-Ahead Log for the cached module source database.
This brings SQLite connection cost on startup from 2.5% to 1.6%.
I'm still hesitant about it as disabling WAL might have negavitve
impact on multiple Deno processes running in parallel (ie. it may
cause module cache to become out of sync between processes
leading to strange transpilation bugs).