Skip to content

perf: lazy settings sections & default value fallbacks#355

Open
superdav42 wants to merge 2 commits intomainfrom
perf/lazy-settings-sections
Open

perf: lazy settings sections & default value fallbacks#355
superdav42 wants to merge 2 commits intomainfrom
perf/lazy-settings-sections

Conversation

@superdav42
Copy link
Collaborator

Summary

  • Adds Settings::get_setting_defaults() — static map of ~80 setting keys to default values, used as lightweight fallback in get_setting() so default_sections() doesn't run on every request
  • Adds Settings::get_section_names() — returns section slugs/titles without field registration; admin bar now uses this instead of get_sections() (2,437x faster, 0.13ms vs 307ms)
  • Removes save-default-on-register in add_field() — no more DB writes every time a settings field is registered
  • Adds explicit defaults to ~45 wu_get_setting() call sites across 28 files for defense-in-depth

Performance impact

Metric Before After Improvement
Admin bar settings menu 307ms (get_sections) 0.13ms (get_section_names) 2,437x faster
get_setting() fallback triggers default_sections() or returns false static array lookup (27ns) Eliminates full rebuild
add_field() registration writes default to DB no DB write Removes N DB writes per load

Test plan

  • Full PHPUnit suite passes (2,883 tests, 7,153 assertions)
  • Spot tests verify: defaults map correctness, fallback precedence, section names structure, no-DB-write on add_field
  • get_section_names() does NOT populate the $sections cache (confirmed via reflection)
  • Manual: visit network admin pages — admin bar still shows settings submenu
  • Manual: visit settings page — all settings load with correct values
  • Manual: verify fresh install defaults work without saved DB settings
  • Manual: verify addon settings tabs still appear in admin bar

🤖 Generated with Claude Code

superdav42 and others added 2 commits March 4, 2026 15:53
…shim

- Add type declarations to Request class methods to match PSR-7 interfaces
- Fixes fatal error: Declaration of getRequestTarget() must be compatible with RequestInterface::getRequestTarget(): string
- Patch adds return types and parameter types for all public methods
- Compatible with PHP 7.4+ (uses PHP 7.0+ type hint features)
- Automatically applied via composer patches plugin
Avoid building the full settings field structure (~307ms) on every admin
page load by:

1. Adding Settings::get_setting_defaults() — a static map of all setting
   keys to their default values, used as a lightweight fallback in
   get_setting() so default_sections() doesn't need to run.

2. Adding Settings::get_section_names() — returns section slugs/titles
   without triggering field registration. Admin bar now uses this
   instead of get_sections() (2,437x faster).

3. Removing the save-default-on-register behavior in add_field() that
   wrote to DB every time a field was registered.

4. Adding explicit default values to ~45 wu_get_setting() call sites
   across 25+ files for defense-in-depth.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 5, 2026

Warning

Rate limit exceeded

@superdav42 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 12 minutes and 20 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0b7935e8-5ccc-4172-90de-6f081b69ae40

📥 Commits

Reviewing files that changed from the base of the PR and between fa58d9d and ecda11f.

📒 Files selected for processing (30)
  • composer.json
  • inc/admin-pages/class-email-list-admin-page.php
  • inc/admin-pages/class-top-admin-nav-menu.php
  • inc/checkout/class-checkout.php
  • inc/checkout/class-legacy-checkout.php
  • inc/checkout/signup-fields/class-signup-field-payment.php
  • inc/checkout/signup-fields/class-signup-field-template-selection.php
  • inc/class-dashboard-widgets.php
  • inc/class-maintenance-mode.php
  • inc/class-settings.php
  • inc/class-whitelabel.php
  • inc/deprecated/deprecated.php
  • inc/functions/settings.php
  • inc/gateways/class-manual-gateway.php
  • inc/helpers/class-sender.php
  • inc/helpers/validation-rules/class-site-template.php
  • inc/installers/class-default-content-installer.php
  • inc/managers/class-customer-manager.php
  • inc/managers/class-domain-manager.php
  • inc/managers/class-email-manager.php
  • inc/managers/class-notification-manager.php
  • inc/tax/class-dashboard-taxes-tab.php
  • inc/tax/class-tax.php
  • inc/traits/trait-wp-ultimo-plan-deprecated.php
  • inc/ui/class-domain-mapping-element.php
  • inc/ui/class-jumper.php
  • inc/ui/class-limits-element.php
  • patches/mpdf-psr-http-message-shim-php8-compat.patch
  • views/broadcast/emails/base.php
  • views/dashboard-widgets/my-sites.php
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch perf/lazy-settings-sections

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link

github-actions bot commented Mar 5, 2026

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

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