Improve initialization performance: make sanitize_slug no-op #1091
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Approach
I noticed that on every single wordpress page load, Cloudinary adds quite a bit of overhead (3.4s with xdebug.trace_format=3 enabled; probably 1/4 of that in real life). Of that, 1.1s was
get_site_url(which I can optimize on my end), 520ms was telemetry, and 1.2s wasCloudinary\Settings->get_default_settings.So I asked @openai/codex (gpt-5 high) to optimize the page load.
Remove expensive function
sanitize_file_namefromsanitize_slugand makesanitize_slugthe identity function. Apparentlysanitize_slugserves no purpose.Proof slugs are controlled (code-defined) and not untrusted user input
Params_Traitis mixed into these classes:Settings(php/class-settings.php),Setting(php/settings/class-setting.php),Admin(php/class-admin.php),Assets(php/class-assets.php).Settings::__construct()andget_default_settings(): slugs come from arrays defined in ui-definitions/*.php and component params.Connect::register_meta()(php/class-connect.php) registers data options with explicit option_name values (e.g. '_cloudinary_history').Admin::rest_save_settings()only saves whitelisted keys: it filters->get_params()so that only keys for which->get_setting(, false)exists are processed. Users never supply arbitrary keys.Assetsuses a custom separator '/' and normalizes keys viaclean_path();keys are URL-like but only used in-memory to map asset parents. Bothsetandgetuse the same function, so consistency is preserved.error_logany timesanitize_slugchanged anything during plugin init, it found that the following were the only keys that changed. And I found no references in the code to any of those keys without the leading underscore.@data._cloudinary_usage->@data.cloudinary_usage@data._cloudinary_last_usage->@data.cloudinary_last_usage@data._cloudinary_settings_version->@data.cloudinary_settings_version@data._cloudinary_history->@data.cloudinary_historyProof no DB migration is necessary
sanitize_slug():Setting::save_value()->Settings::save_setting()->Settings\Storage\Options::save().Options::save()callsupdate_option(->prefix(), ->get(), false).Setting::get_option_name()returns the first segment of the stored 'storage_path' value (php/settings/class-setting.php).Storage::prefix()preserves leading_option names (php/settings/storage/class-storage.php), so e.g. '_cloudinary_history' stays as-is.update_option()with explicit names inConnect(php/class-connect.php), bypassingParams_Traitentirely.sanitize_slug()ever changed was ephemeral, in-memory param keys like@data._cloudinary_history->@data.cloudinary_history. Those params are rebuilt each request and are not persisted towp_options. Reads and writes always compute the same path on a given request, so changing the sanitizer does not require migrating any persisted structure.Backwards compatibility / risk assessment
@data,@pending,@submissionretain their original segment names (including leading underscores). All callers thatset_param/get_paramthose keys use the same method within the same request, so no mismatch is possible.option_namevalues are defined in code.clean_path()and improves lookup stability.Expected impact
QA notes