Skip to content

i18n-calypso: Replace EventEmitter with simplified subscriber callbacks #103304

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: trunk
Choose a base branch
from

Conversation

aduth
Copy link
Member

@aduth aduth commented May 9, 2025

Proposed Changes

  • Removes EventEmitter usage from i18n-calypso package, substituting a simplified subscriber implementation

Why are these changes being made?

On performance, I discovered that the events library does have a surprisingly-performant subscriber removal behavior. Early iterations here included a "readable" Array#filter implementation (see a8fb2d4), but considering that many of our localized components will remove event listeners once they're unmounted, it seemed worthwhile to micro-optimize. After several rounds of micro-benchmarking, I found a solution which performs even better (~38%) than events's implementation, and ~850x better than a naive Array#filter implementation in a scenario with 2000 subscribers.

Separately, I had explored an implementation which largely maintained the same API if we'd rather reduce the scope of the changes.

Testing Instructions

  • The idea is that this should be drop-in compatible for localization, and should have no impact on the display and re-rendering of translation data. Changes can be emulated by switching languages in the dashboard.

Pre-merge Checklist

  • Has the general commit checklist been followed? (PCYsg-hS-p2)
  • Have you written new tests for your changes?
  • Have you tested the feature in Simple (P9HQHe-k8-p2), Atomic (P9HQHe-jW-p2), and self-hosted Jetpack sites (PCYsg-g6b-p2)?
  • Have you checked for TypeScript, React or other console errors?
  • Have you used memoizing on expensive computations? More info in Memoizing with create-selector and Using memoizing selectors and Our Approach to Data
  • Have we added the "[Status] String Freeze" label as soon as any new strings were ready for translation (p4TIVU-5Jq-p2)?
    • For UI changes, have we tested the change in various languages (for example, ES, PT, FR, or DE)? The length of text and words vary significantly between languages.
  • For changes affecting Jetpack: Have we added the "[Status] Needs Privacy Updates" label if this pull request changes what data or activity we track or use (p4TIVU-aUh-p2)?

@aduth aduth requested a review from a team May 9, 2025 19:27
@aduth aduth requested a review from a team as a code owner May 9, 2025 19:27
@matticbot matticbot added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label May 9, 2025
@matticbot
Copy link
Contributor

This PR modifies the release build for the following Calypso Apps:

For info about this notification, see here: PCYsg-OT6-p2

  • blaze-dashboard
  • command-palette-wp-admin
  • happy-blocks
  • help-center
  • notifications
  • odyssey-stats
  • wpcom-block-editor

To test WordPress.com changes, run install-plugin.sh $pluginSlug remove/i18n-events-dep on your sandbox.

@matticbot
Copy link
Contributor

matticbot commented May 9, 2025

Here is how your PR affects size of JS and CSS bundles shipped to the user's browser:

App Entrypoints (~134 bytes removed 📉 [gzipped])

name                   parsed_size           gzip_size
entry-subscriptions         -280 B  (-0.0%)      -85 B  (-0.0%)
entry-login                 -280 B  (-0.0%)      -82 B  (-0.0%)
entry-main                  -260 B  (-0.0%)      -68 B  (-0.0%)
entry-reauth-required       -258 B  (-0.0%)      -65 B  (-0.0%)
entry-stepper               -219 B  (-0.0%)      -53 B  (-0.0%)
entry-domains-landing       -174 B  (-0.0%)      -15 B  (-0.0%)

Common code that is always downloaded and parsed every time the app is loaded, no matter which route is used.

Sections (~241 bytes removed 📉 [gzipped])

name                                parsed_size           gzip_size
stepper-user-step                         -61 B  (-0.0%)      -28 B  (-0.0%)
async-step-use-my-domain                  -61 B  (-0.0%)      -31 B  (-0.0%)
async-step-unified-plans                  -61 B  (-0.0%)      -27 B  (-0.0%)
async-step-unified-domains                -61 B  (-0.0%)      -28 B  (-0.0%)
site-migration-flow                       -41 B  (-0.1%)      -20 B  (-0.1%)
woocommerce-installation                  -20 B  (-0.0%)      -15 B  (-0.0%)
woocommerce                               -20 B  (-0.0%)      -15 B  (-0.0%)
themes                                    -20 B  (-0.0%)      -15 B  (-0.0%)
theme                                     -20 B  (-0.0%)      -15 B  (-0.0%)
subscribers                               -20 B  (-0.0%)      -15 B  (-0.0%)
stats                                     -20 B  (-0.0%)      -15 B  (-0.0%)
staging-site                              -20 B  (-0.0%)      -13 B  (-0.0%)
sites-dashboard                           -20 B  (-0.0%)      -13 B  (-0.0%)
site-settings                             -20 B  (-0.0%)      -13 B  (-0.0%)
site-purchases                            -20 B  (-0.0%)      -10 B  (-0.0%)
site-profiler                             -20 B  (-0.0%)      -15 B  (-0.0%)
site-performance                          -20 B  (-0.0%)      -13 B  (-0.0%)
site-monitoring                           -20 B  (-0.0%)      -13 B  (-0.0%)
site-logs                                 -20 B  (-0.0%)      -13 B  (-0.0%)
site-blocks                               -20 B  (-0.0%)      -15 B  (-0.0%)
settings-writing                          -20 B  (-0.0%)      -15 B  (-0.0%)
settings-security                         -20 B  (-0.0%)      -15 B  (-0.0%)
settings-reading                          -20 B  (-0.0%)      -15 B  (-0.0%)
settings-podcast                          -20 B  (-0.0%)      -15 B  (-0.0%)
settings-performance                      -20 B  (-0.0%)      -15 B  (-0.0%)
settings-newsletter                       -20 B  (-0.0%)      -15 B  (-0.0%)
settings-jetpack                          -20 B  (-0.0%)      -15 B  (-0.0%)
settings-discussion                       -20 B  (-0.0%)      -15 B  (-0.0%)
settings                                  -20 B  (-0.0%)      -15 B  (-0.0%)
security                                  -20 B  (-0.0%)      -15 B  (-0.0%)
scan                                      -20 B  (-0.0%)      -15 B  (-0.0%)
reader                                    -20 B  (-0.0%)      -14 B  (-0.0%)
purchases                                 -20 B  (-0.0%)      -10 B  (-0.0%)
purchase-product                          -20 B  (-0.0%)      -15 B  (-0.0%)
promote-post-i2                           -20 B  (-0.0%)      -15 B  (-0.0%)
privacy                                   -20 B  (-0.0%)      -15 B  (-0.0%)
posts-custom                              -20 B  (-0.0%)      -15 B  (-0.0%)
posts                                     -20 B  (-0.0%)      -15 B  (-0.0%)
plugins                                   -20 B  (-0.0%)      -13 B  (-0.0%)
plans                                     -20 B  (-0.0%)      -13 B  (-0.0%)
performance-profiler                      -20 B  (-0.0%)      -15 B  (-0.0%)
people                                    -20 B  (-0.0%)      -15 B  (-0.0%)
patterns                                  -20 B  (-0.0%)      -13 B  (-0.0%)
pages                                     -20 B  (-0.0%)      -15 B  (-0.0%)
overview                                  -20 B  (-0.0%)      -13 B  (-0.0%)
notification-settings                     -20 B  (-0.0%)      -15 B  (-0.0%)
migrate                                   -20 B  (-0.0%)      -15 B  (-0.0%)
media                                     -20 B  (-0.0%)      -15 B  (-0.0%)
me                                        -20 B  (-0.0%)      -15 B  (-0.0%)
marketplace                               -20 B  (-0.0%)      -15 B  (-0.0%)
marketing                                 -20 B  (-0.0%)      -15 B  (-0.0%)
jetpack-social                            -20 B  (-0.0%)      -15 B  (-0.0%)
jetpack-search                            -20 B  (-0.0%)      -15 B  (-0.0%)
jetpack-connect                           -20 B  (-0.0%)      -15 B  (-0.0%)
jetpack-cloud-settings                    -20 B  (-0.0%)      -15 B  (-0.0%)
jetpack-cloud-pricing                     -20 B  (-0.0%)      -15 B  (-0.0%)
jetpack-cloud-plugin-management           -20 B  (-0.0%)      -13 B  (-0.0%)
jetpack-cloud-partner-portal              -20 B  (-0.0%)      -15 B  (-0.0%)
jetpack-cloud-overview                    -20 B  (-0.0%)      -15 B  (-0.0%)
jetpack-cloud-manage-pricing              -20 B  (-0.0%)      -15 B  (-0.0%)
jetpack-cloud-features-comparison         -20 B  (-0.0%)      -15 B  (-0.0%)
jetpack-cloud-agency-signup               -20 B  (-0.0%)      -15 B  (-0.1%)
jetpack-cloud-agency-dashboard            -20 B  (-0.0%)      -15 B  (-0.0%)
jetpack-cloud                             -20 B  (-0.0%)      -15 B  (-0.0%)
jetpack-app                               -20 B  (-0.0%)      -15 B  (-0.0%)
import                                    -20 B  (-0.0%)      -15 B  (-0.0%)
hosting                                   -20 B  (-0.0%)      -13 B  (-0.0%)
home                                      -20 B  (-0.0%)      -15 B  (-0.0%)
help                                      -20 B  (-0.0%)      -15 B  (-0.0%)
gutenberg-editor                          -20 B  (-0.0%)      -15 B  (-0.0%)
google-my-business                        -20 B  (-0.0%)      -15 B  (-0.0%)
github-deployments                        -20 B  (-0.0%)      -13 B  (-0.0%)
export                                    -20 B  (-0.0%)      -15 B  (-0.0%)
entrepreneur-flow                         -20 B  (-0.0%)      -15 B  (-0.0%)
email                                     -20 B  (-0.0%)      -15 B  (-0.0%)
earn                                      -20 B  (-0.0%)      -15 B  (-0.0%)
domains                                   -20 B  (-0.0%)      -13 B  (-0.0%)
developer                                 -20 B  (-0.0%)      -15 B  (-0.0%)
customize                                 -20 B  (-0.0%)      -15 B  (-0.0%)
concierge                                 -20 B  (-0.0%)      -15 B  (-0.0%)
comments                                  -20 B  (-0.0%)      -15 B  (-0.0%)
checkout                                  -20 B  (-0.0%)      -15 B  (-0.0%)
backup                                    -20 B  (-0.0%)      -15 B  (-0.0%)
add-ons                                   -20 B  (-0.0%)      -15 B  (-0.0%)
activity                                  -20 B  (-0.0%)      -15 B  (-0.0%)
account-close                             -20 B  (-0.0%)      -15 B  (-0.0%)
account                                   -20 B  (-0.0%)      -15 B  (-0.0%)
a8c-for-agencies-woopayments              -20 B  (-0.0%)      -16 B  (-0.0%)
a8c-for-agencies-team                     -20 B  (-0.0%)      -14 B  (-0.0%)
a8c-for-agencies-sites                    -20 B  (-0.0%)      -11 B  (-0.0%)
a8c-for-agencies-settings                 -20 B  (-0.0%)      -15 B  (-0.0%)
a8c-for-agencies-referrals                -20 B  (-0.0%)      -15 B  (-0.0%)
a8c-for-agencies-purchases                -20 B  (-0.0%)      -15 B  (-0.0%)
a8c-for-agencies-plugins                  -20 B  (-0.0%)      -13 B  (-0.0%)
a8c-for-agencies-partner-directory        -20 B  (-0.0%)      -15 B  (-0.0%)
a8c-for-agencies-overview                 -20 B  (-0.0%)      -11 B  (-0.0%)
a8c-for-agencies-migrations               -20 B  (-0.0%)      -17 B  (-0.0%)
a8c-for-agencies-marketplace              -20 B  (-0.0%)      -15 B  (-0.0%)
a8c-for-agencies-landing                  -20 B  (-0.0%)      -15 B  (-0.0%)
a8c-for-agencies-client                   -20 B  (-0.0%)      -14 B  (-0.0%)
a8c-for-agencies-agency-tier              -20 B  (-0.0%)      -15 B  (-0.0%)
a8c-for-agencies                          -20 B  (-0.0%)      -15 B  (-0.0%)

Sections contain code specific for a given set of routes. Is downloaded and parsed only when a particular route is navigated to.

Async-loaded Components (~51 bytes removed 📉 [gzipped])

name                                                                              parsed_size           gzip_size
async-load-automattic-help-center-stepper                                               -61 B  (-0.0%)      -32 B  (-0.0%)
async-load-signup-steps-woocommerce-install-transfer                                    -20 B  (-0.0%)      -15 B  (-0.1%)
async-load-signup-steps-woocommerce-install-step-store-address                          -20 B  (-0.0%)      -15 B  (-0.0%)
async-load-signup-steps-woocommerce-install-step-business-info                          -20 B  (-0.0%)      -15 B  (-0.0%)
async-load-signup-steps-woocommerce-install-confirm                                     -20 B  (-0.0%)      -15 B  (-0.1%)
async-load-signup-steps-website-content-section-types                                   -20 B  (-0.0%)      -15 B  (-0.1%)
async-load-signup-steps-website-content                                                 -20 B  (-0.0%)      -15 B  (-0.0%)
async-load-signup-steps-user                                                            -20 B  (-0.0%)      -15 B  (-0.0%)
async-load-signup-steps-store-features                                                  -20 B  (-0.0%)      -15 B  (-0.1%)
async-load-signup-steps-starting-point                                                  -20 B  (-0.0%)      -15 B  (-0.1%)
async-load-signup-steps-social-profiles                                                 -20 B  (-0.0%)      -15 B  (-0.1%)
async-load-signup-steps-site-picker                                                     -20 B  (-0.0%)      -15 B  (-0.0%)
async-load-signup-steps-site-or-domain                                                  -20 B  (-0.0%)      -15 B  (-0.1%)
async-load-signup-steps-site-options                                                    -20 B  (-0.0%)      -15 B  (-0.1%)
async-load-signup-steps-site                                                            -20 B  (-0.0%)      -15 B  (-0.1%)
async-load-signup-steps-rewind-were-backing                                             -20 B  (-0.0%)      -15 B  (-0.1%)
async-load-signup-steps-rewind-form-creds                                               -20 B  (-0.0%)      -15 B  (-0.0%)
async-load-signup-steps-plans-theme-preselected                                         -20 B  (-0.0%)      -15 B  (-0.0%)
async-load-signup-steps-plans                                                           -20 B  (-0.0%)      -15 B  (-0.0%)
async-load-signup-steps-page-picker                                                     -20 B  (-0.0%)      -15 B  (-0.0%)
async-load-signup-steps-new-or-existing-site                                            -20 B  (-0.0%)      -15 B  (-0.1%)
async-load-signup-steps-intent                                                          -20 B  (-0.0%)      -15 B  (-0.1%)
async-load-signup-steps-hosting-decider                                                 -20 B  (-0.0%)      -15 B  (-0.1%)
async-load-signup-steps-emails                                                          -20 B  (-0.0%)      -15 B  (-0.1%)
async-load-signup-steps-domains                                                         -20 B  (-0.0%)      -15 B  (-0.0%)
async-load-signup-steps-difm-site-picker                                                -20 B  (-0.0%)      -15 B  (-0.0%)
async-load-signup-steps-design-picker                                                   -20 B  (-0.0%)      -15 B  (-0.1%)
async-load-signup-steps-creds-permission                                                -20 B  (-0.0%)      -15 B  (-0.1%)
async-load-signup-steps-creds-confirm                                                   -20 B  (-0.0%)      -15 B  (-0.1%)
async-load-signup-steps-courses                                                         -20 B  (-0.0%)      -15 B  (-0.1%)
async-load-signup-steps-clone-start                                                     -20 B  (-0.0%)      -15 B  (-0.1%)
async-load-signup-steps-clone-ready                                                     -20 B  (-0.0%)      -15 B  (-0.1%)
async-load-signup-steps-clone-point                                                     -20 B  (-0.0%)      -15 B  (-0.0%)
async-load-signup-steps-clone-destination                                               -20 B  (-0.0%)      -15 B  (-0.1%)
async-load-signup-steps-clone-credentials                                               -20 B  (-0.0%)      -15 B  (-0.0%)
async-load-signup-steps-clone-cloning                                                   -20 B  (-0.0%)      -15 B  (-0.1%)
async-load-purchase-modal-wrapper                                                       -20 B  (-0.0%)      -15 B  (-0.0%)
async-load-my-sites-checkout-purchase-modal-is-eligible-for-one-click-checkou...        -20 B  (-0.0%)      -15 B  (-0.0%)
async-load-masterbar-cart-masterbar-cart-wrapper                                        -20 B  (-0.0%)      -15 B  (-0.0%)
async-load-design-playground                                                            -20 B  (-0.0%)      -15 B  (-0.0%)
async-load-design-blocks                                                                -20 B  (-0.0%)      -10 B  (-0.0%)
async-load-design                                                                       -20 B  (-0.0%)      -15 B  (-0.0%)
async-load-calypso-notifications                                                        -20 B  (-0.0%)      -15 B  (-0.0%)
async-load-calypso-blocks-support-article-dialog-dialog                                 -20 B  (-0.0%)      -16 B  (-0.0%)
async-load-calypso-blocks-jitm-templates-home-task                                      -20 B  (-0.0%)      -15 B  (-0.1%)
async-load-automattic-help-center                                                       -20 B  (-0.0%)      -15 B  (-0.0%)
async-load-calypso-layout-community-translator                                          +11 B  (+0.0%)       +7 B  (+0.1%)

React components that are loaded lazily, when a certain part of UI is displayed for the first time.

Legend

What is parsed and gzip size?

Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory.
Gzip Size: Compressed size of the JS and CSS files. This much data needs to be downloaded over network.

Generated by performance advisor bot at iscalypsofastyet.com.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants