Viewing media in grid mode is unresponsive/very slow
-
Hi,
We got a problem in viewing media with grid mode. It takes very long to load all the images and their information, usually around 24 – 30 seconds on Google App Engine and Google Cloud Storage. Disabling this plugin can reduce the time to 2-3 seconds. Debugging showed that the bottleneck is at line 329, modules/uploads.php. Executing this line usually takes 0.5 – 0.8 seconds.
$file = get_attached_file( $id );
It is quite strange that get_attached_file with the same ID has been called before this line and is very fast. Tracing deep down to the get_attached_file function, which calls wp_upload_dir, in which wp_mkdir_p will be invoked. In wp_mkdir_p, we recognised that is_dir call is actually the root cause, accounting for most of the time taken. It seems this bug has something to do the underlying implementation of is_dir in Php Google App Engine. We thought there must be some caching mechanism behind it.
Have anyone encountered this? Do you have any suggestions or ideas that could be taken? At the moment, we use a hacky solution by adding is_writable check along with is_dir as following. It turned out that is_writable is far more faster than is_dir under Google App Engine.
// Workaround for GCS. // as is_dir consumes too much time in Google App Engine and Cloud Storage // we check if the directory is writable or not. if ( file_exists( $target ) ) return is_writable($target) || @is_dir( $target );
It is also a question for WordPress. It seems very inefficient in calling wp_mkdir_p every time we call get_attached_file. is_dir may be very fast in dealing with local environments but working with remote Cloud Storage would incur high latency.
- The topic ‘Viewing media in grid mode is unresponsive/very slow’ is closed to new replies.