Okay, let's break down the warning and the decision of whether to move your uv cache.
Understanding the Warning
The warning "Failed to hardlink files; falling back to full copy" means uv tried to create a hard link from its cache directory to your project's installation directory (likely within a virtual environment).
- Hard Linking: This is a filesystem feature where two directory entries (files) point to the exact same data block on the disk. It's very fast because no data is actually copied; only a new pointer (directory entry) is created. It also saves disk space, as the data exists only once.
- The Constraint: Hard links can only be created between files residing on the same physical filesystem.
- Your Situation: Your
uv cache is on Filesystem A (where Arch Linux is installed), and your codebase (and likely the installation target, e.g., a virtual environment) is on Filesystem B (your other partition). Since A != B, uv cannot create hard links.
- The Fallback:
uv then resorts to copying the package files from the cache (Filesystem A) to your project directory (Filesystem B). This works, but it's slower and uses more disk space temporarily (though the space is used on Filesystem B).
Moving the uv Cache to Your Codebase Filesystem
The idea is to set the UV_CACHE_DIR environment variable (or use a config file) to point to a location within the filesystem where your codebase resides.
How to do it:
You would typically set an environment variable before running uv commands, for example:
export UV_CACHE_DIR="/path/to/your/codebase/partition/.uv_cache"
# Now run your uv commands
uv pip install ...
Or add it to your shell profile (.bashrc, .zshrc, etc.) if you always want it set.
Pros of Moving the Cache:
- Enables Hard Linking: If both the cache and your project's installation target (e.g.,
venv/lib/pythonX.Y/site-packages/) are on the same filesystem (your codebase partition), uv can now use hard links.
- Improved Performance: Hard linking is significantly faster than copying, especially for large packages or projects with many small files. This speeds up package installation and updates.
- Reduced I/O (Potentially): Hard linking involves minimal disk I/O compared to copying. If your codebase partition is slower (e.g., an HDD vs. an NVMe SSD for the OS), avoiding large copies to it might be beneficial, although accessing the cache from it could still be a bottleneck (see cons). If both are fast SSDs, hardlinking is definitely the winner.
Cons of Moving the Cache:
- Performance on Slower Filesystems: If your codebase partition is slower than the partition where Arch Linux is installed (e.g., codebase on HDD, OS on NVMe SSD), moving the cache there might actually slow down installations. Even with hardlinking, the underlying data access speed matters. Copying from a fast OS drive to a slow project drive is slow, but accessing packages via hard links on a slow drive might also be slow. The ideal scenario for hardlinking is cache and target on the same fast filesystem.
- Cache Location & Management: The
uv cache is intended to be a central repository. Moving it tied to one specific codebase's partition might feel less "clean" than the default location (~/.cache/uv). If you work on projects across multiple different filesystems, you might need different cache locations or face the same hardlinking issue again.
- Disk Space Usage: The cache will now consume space on your codebase partition. Ensure it has enough free space. While hardlinking saves space compared to copying within the install process, the cache itself still stores the package data.
- Potential for Cross-Contamination: Mixing build/cache artifacts directly with your source code isn't always ideal, though placing it in a hidden directory like
.uv_cache mitigates this visually.
Recommendation
-
Assess Filesystem Speed: Is your codebase partition an SSD/NVMe or an HDD?
- If it's an HDD and your OS partition is an SSD/NVMe, do not move the cache. The performance gains from hardlinking are unlikely to outweigh the slow read speeds from the HDD cache, and copying from the fast OS drive might actually be faster overall. In this case, accept the copy behavior or use
UV_LINK_MODE=copy to suppress the warning.
- If your codebase partition is also a fast SSD/NVMe, moving the cache might offer a slight performance benefit, especially if you perform many installs/updates. However, the difference might be marginal.
-
Consider Simplicity: The default cache location is usually fine. The warning indicates a suboptimal performance path (copying), but unless you're seeing significant delays during package installations, it might not be worth changing the cache location and potentially complicating management.
-
Easiest Solution: The simplest way to deal with the warning if the performance impact is negligible is to explicitly tell uv to always copy:
export UV_LINK_MODE=copy
# or
uv --link-mode copy install ...
This suppresses the warning without changing where uv looks for its cache, keeping things organised.
Conclusion:
Moving the cache is primarily a performance optimization that enables hardlinking. Evaluate if the potential speed increase is worth the potential downsides (managing cache location, possible slowdown if the target partition is slow). If your codebase partition is an HDD, stick with the default or use UV_LINK_MODE=copy. If it's also a fast SSD, moving the cache is a viable option, but consider if the complexity outweighs the potential minor speed boost.