[wp-trac] [WordPress Trac] #51981: wp_unique_filename() performance issue

WordPress Trac noreply at wordpress.org
Wed Dec 9 10:08:07 UTC 2020


#51981: wp_unique_filename() performance issue
--------------------------+-----------------------------
 Reporter:  deividasjank  |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Media         |    Version:  5.5.3
 Severity:  major         |   Keywords:
  Focuses:  performance   |
--------------------------+-----------------------------
 Hello. I am new in this community and this is my first ticket, so don't
 judge me :)

 Recently I have updated our project's WP from 4.9.8 to 5.5.3. We have
 noticed that image upload time has significantly increased from 2s to 20s.
 We are using S3 upload and our images count is huge.

 Then I have noticed that wp_unique_filename() logic has been changed.
 Basically all of the upload time is consumed by @scandir(). We have a lot
 of files so this is not performing well.

 {{{#!php
 <?php
 if ( null === $files ) {
   // List of all files and directories contained in $dir.
   $files = @scandir( $dir );
 }
 }}}

 Then I have tried to revert this function to previous version and that
 solution to check one file at a time was performing much better.

 {{{#!php
 <?php
 while ( file_exists( $dir . "/$filename" ) ) {...
 }}}


 I think this performance issue should be fixed.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/51981>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list