fix(perf): reduce Akamai CryptoJS bundle size - #1877
Conversation
Import only the CryptoJS modules required for SHA-1, SHA-256, HMAC, and Base64 support, and cover the supported hash and encoding combinations. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Edit:Did some other tests in the sandbox and I found tha a cold EdgeWorker initialization dropped from ~41.4ms to ~31.9ms after this change, roughly a 23% reduction. Warm runs have no init cost. These are sandbox results, so we still need production data to quantify the real-world impact. |
|
Hi @jthorupp - thank you for the contribution! I went ahead and change the title prefix to |
|
CI failures are due to forked PRs not having access to super secret stuff (expected). I am going to merge this since I think there are good fixes here. Thanks @jthorupp! Be on the look out for a new patch version later today. I've created internal tickets for you other suggestions as well. I would expect a small patch soon for the targeted |
Thanks for merging! I'll be on the lookout for more optimisations and post suggestions if I find any 🙂 |
🤖 I have created a release *beep* *boop* --- <details><summary>akamai-edgeworker-sdk-common: 2.0.30</summary> ## [2.0.30](akamai-edgeworker-sdk-common-v2.0.29...akamai-edgeworker-sdk-common-v2.0.30) (2026-08-25) ### Bug Fixes * **perf:** reduce Akamai CryptoJS bundle size ([#1877](#1877)) ([0b3e1ec](0b3e1ec)) </details> <details><summary>akamai-server-base-sdk: 3.0.31</summary> ## [3.0.31](akamai-server-base-sdk-v3.0.30...akamai-server-base-sdk-v3.0.31) (2026-08-25) ### Dependencies * The following workspace dependencies were updated * dependencies * @launchdarkly/akamai-edgeworker-sdk-common bumped from ^2.0.29 to ^2.0.30 </details> <details><summary>akamai-server-edgekv-sdk: 1.4.33</summary> ## [1.4.33](akamai-server-edgekv-sdk-v1.4.32...akamai-server-edgekv-sdk-v1.4.33) (2026-08-25) ### Dependencies * The following workspace dependencies were updated * dependencies * @launchdarkly/akamai-edgeworker-sdk-common bumped from ^2.0.29 to ^2.0.30 </details> --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Overview** > Release Please version bump for three Akamai packages, with no new runtime logic in this diff beyond synced `sdkVersion` strings and dependency pins. > > **@launchdarkly/akamai-edgeworker-sdk-common** goes to **2.0.30**, carrying the already-merged **perf** fix that shrinks the CryptoJS footprint (narrow imports instead of pulling the full library — see [#1877](#1877)). > > **@launchdarkly/akamai-server-base-sdk** (**3.0.31**) and **@launchdarkly/akamai-server-edgekv-sdk** (**1.4.33**) are dependency-only releases that bump `@launchdarkly/akamai-edgeworker-sdk-common` to **^2.0.30**, plus matching changelog entries, `.release-please-manifest.json`, and example `package.json` pins. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 49a824d. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Requirements
Related issues
Raised from a customer report that Akamai SDK initialization consumes approximately 45 ms of a 60 ms initialization CPU budget.
Describe the solution you've provided
Replace the
crypto-jsroot import with targeted imports for core, SHA-1, SHA-256, HMAC, and Base64. This avoids bundling unused ciphers, hash algorithms, modes, and padding implementations while preserving the existing synchronous crypto API.The HMAC implementation now also accesses Base64 and Hex through the imported CryptoJS namespace instead of the undeclared
CryptoJSglobal. Direct test vectors cover SHA-1 and SHA-256 hashes and HMACs in both Hex and Base64.Describe alternatives you've considered
Targeted
semverimports and publishing an unbundled ESM entry point could provide additional savings, but they affect shared SDK behavior or the public package layout. They are intentionally excluded so this PR remains a low-risk import-graph optimization matching the approach already accepted for the Fastly SDK in #1795.Additional context
Measured after building with:
yarn workspaces foreach -pR --topological-dev --from '@launchdarkly/akamai-server-edgekv-sdk' run buildValidated with the common Akamai SDK and EdgeKV SDK unit tests and lint checks.
Note
Overview
Shrinks the Akamai EdgeKV SDK bundle by replacing the full
crypto-jsentry import withcrypto-js/coreplus side-effect imports for SHA-1, SHA-256, HMAC, and Base64 only, so unused ciphers and algorithms are not pulled into the build (reported ~21% smaller raw artifacts and ~28% smaller gzip).CryptoJSHasherandCryptoJSHmacnow resolve algorithms and encodings through the importedCryptoJSnamespace (CryptoJS.algo.*,CryptoJS.enc.*) instead of separatecrypto-jssubpath default imports. HMAC digest encoding follows the same pattern, removing reliance on an implicit globalCryptoJSfor Base64/Hex.Adds
crypto.test.tswith fixed vectors for SHA-1 and SHA-256 hashes and HMACs in hex and base64 to lock behavior after the import change.Reviewed by Cursor Bugbot for commit c7b98a6. Bugbot is set up for automated code reviews on this repo. Configure here.