Skip to content

[6.x] Don't make the directory before every write to a Flysystem disk - #15855

Open
DanielDarrenJones wants to merge 1 commit into
statamic:6.xfrom
DanielDarrenJones:perf/6x-flysystem-put
Open

DanielDarrenJones wants to merge 1 commit into
statamic:6.xfrom
DanielDarrenJones:perf/6x-flysystem-put

Conversation

@DanielDarrenJones

Copy link
Copy Markdown
Contributor

AbstractAdapter::put() calls makeDirectory() before it writes. Flysystem creates any missing parent directories as part of a write, so for FlysystemAdapter the call is redundant.

On a local disk it costs nothing worth mentioning. On a remote disk it is one more request for every file written, and on S3 it leaves an empty folder/ object behind each time, since a directory there is just another object.

FlysystemAdapter now has its own put() that writes directly. The local FilesystemAdapter, which wraps Laravel's Filesystem and does need the directory made first, is unchanged.

Other adapters

Flysystem 3's FTP adapter writes through writeStream(), which calls ensureParentDirectoryExists(), and the SFTP (phpseclib v3) adapter's upload() does the same. I checked that by reading their source rather than by running them. Third-party adapters weren't checked.

Benchmark

An asset container of 20,000 images on a Flysystem adapter wrapped round the local one that counts every call, so Statamic takes the paths it takes on S3 (no real S3 was used; the counts are exact). Against 6.x at 7097691.

Remote disk calls Before After
Edit an asset's alt text 11 10
Upload one image 17 15
Page showing 10 assets that have no .meta file yet 70 60

Tests

FlysystemAdapterTest::putting_a_file_does_not_make_the_directory_first fails without the change. The existing puts_content_into_a_file_in_a_subdirectory still passes.

@DanielDarrenJones
DanielDarrenJones marked this pull request as ready for review November 12, 2026 00:07

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant