Is npm install efficient with agentfs?

main
8b8f888Add FAQ entry for `git worktrees` (#193)
This post might have stale content, as main is 87 commits ahead.

how efficient is it to run npm install with an agentfs? does it write to sqlite? is that inherently much slower than if it were writing to a real file system?

Avatar of Gemini 3 FlashGemini 3 Flashcommented

Running npm install within an AgentFS environment is efficient enough for development and agent-based tasks, but it is inherently slower than a native filesystem. Here is a breakdown of how it works and its performance characteristics:

###1. Does it write to SQLite?

Yes. AgentFS is designed specifically to store a full POSIX-compliant filesystem within a SQLite database.

  • Every file you create during npm install is stored as an inode entry in the fs_inode table.
  • File contents are broken into chunks (defaulting to 4KB) and stored as BLOBs in the fs_data table.
  • Directory structures are maintained in the fs_dentry table.

###2. Efficiency and "Real" Filesystem Comparison

Running npm install is a "stress test" for any filesystem because it involves creating thousands of small files and directories (the node_modules folder).

  • Inherently Slower: A native filesystem (like EXT4 or APFS) operates at the kernel level with highly optimized data structures. AgentFS adds an abstraction layer (SQL queries, B-Trees within a file, and chunk management), which introduces overhead.
  • Transaction Costs: In a standard database, every file creation would be a transaction. Since npm install creates thousands of files, this could be very slow.

###3. How AgentFS Optimizes Performance

To mitigate the "inherent" slowness of SQLite for this use case, AgentFS employs several optimizations:

  • In-Memory Buffering: The AgentFS sandbox (used when you run commands via agentfs run) buffers file writes in memory. Data is only committed to the SQLite database when a file is closed or fsync is called. This prevents many small database writes for a single file.
  • PRAGMA synchronous = OFF: The SDK configures SQLite with synchronous = OFF. This tells SQLite not to wait for the physical disk to confirm that data has been written to the platter before returning. This provides a massive speed boost for the high-volume writes required by npm install, at the cost of potential database corruption if the host machine crashes mid-operation.
  • Chunked Storage: By splitting files into chunks, AgentFS can handle updates to large files more efficiently than if it had to rewrite the entire file BLOB.

###Summary

FeatureAgentFSNative Filesystem
StorageSingle .db file (SQLite)Thousands of blocks on disk
SpeedModerate (optimized for agents)Extremely Fast
AuditabilityHigh (Query changes with SQL)Low (Requires complex tools)
PortabilityHigh (Move one file)Low (Must tar/zip directories)

Verdict: You will notice a slowdown compared to your host machine, but it is optimized to be "fast enough" so that an AI agent can install dependencies and run Node.js applications without significant friction. The trade-off gives you a portable, auditable, and snapshot-able environment that a real filesystem cannot provide easily.

Avatar of Julian BenegasJulian Benegascommented

what would fast enough be? do you have some estimated timing comparisons? say i'm:

  1. installing dependencies for a medium nextjs repo
  2. running next build on that repo
Avatar of Gemini 3 FlashGemini 3 Flashcommented

While there are no official benchmarks in the repository, we can estimate the performance based on the architecture of AgentFS (SQLite-backed FUSE/NFS) and the specific optimizations implemented in the code.

###1. Dependency Installation (npm install)

Running npm install on a medium Next.js repo is the most demanding task for AgentFS because it involves creating 10,000 to 50,000+ small files and directories.

  • Native Filesystem: ~10–30 seconds (on modern NVMe/SSD).
  • AgentFS Estimate: ~1–3 minutes (roughly 3x to 6x slower).
  • Why?:
    • Metadata Overhead: Every mkdir or file creation in node_modules requires a SQL INSERT into the fs_dentry and fs_inode tables. Even with synchronous = OFF, SQLite’s B-Tree management is more computationally expensive than raw filesystem block allocation.
    • Context Switching: In agentfs run, every filesystem syscall from the npm process must travel from the Kernel → FUSE/NFS Server (AgentFS) → SQLite → Disk and back. These round-trips add up when multiplied by 50,000 files.

###2. Building (next build)

The build process is generally more CPU-bound (Babel/SWC/Webpack/Turbopack) but performs a high volume of stat() and read() calls to crawl the dependency tree.

  • Native Filesystem: ~30–90 seconds.
  • AgentFS Estimate: ~45–120 seconds (roughly 1.2x to 2x slower).
  • Why?:
    • Caching: The AgentFS CLI (specifically the FUSE implementation) uses FUSE_CACHE_SYMLINKS and directory entry caching. Once the dependency tree is mapped, repeated stat() calls are served from memory, significantly closing the gap with native performance.
    • Parallelism: AgentFS supports FUSE_PARALLEL_DIROPS, allowing the build tool to scan multiple directories simultaneously without being bottlenecked by a single-threaded database lock.

###Summary of Performance Features

AgentFS includes several "escape hatches" to ensure it stays within the "fast enough" range for AI agents:

OptimizationEffect
synchronous = OFFMassive boost to write speed; SQLite doesn't wait for the physical disk to stop spinning before moving to the next task.
readdir_plusA custom implementation that fetches entry names and their metadata in a single SQL JOIN, preventing the "N+1 query" problem during directory scans.
Writeback CachingAllows the OS kernel to buffer small writes and send them to AgentFS in larger batches.
Chunked BlobsFiles are stored in 4KB chunks. If a tool updates a small part of a large file, AgentFS only has to update specific rows in the fs_data table rather than rewriting the entire file.

Verdict: If a task takes 20 seconds on your real machine, expect it to take around 60 seconds in AgentFS. For an AI agent environment where auditability, snapshots, and portability are the priorities, this is usually considered "fast enough."


END OF POST

Log in to add a comment
Gemini 3 Flash
Is npm install efficient with agentfs? — tursodatabase/agentfs