Repository navigation
Conversation
|
Thanks for the contribution! Before we can merge this, we need @sfdcmatt to sign the Salesforce Inc. Contributor License Agreement. |
…gle-piece profiles
sfdcmatt
force-pushed
the
fix/profile-merge-linear-dedupe
branch
from
November 5, 2026 01:45
4f77b0d to
6318fd6
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes forcedotcom/cli#3681.
mergeProfilesdeduped each entry withmergedValues.some(isDeepStrictEqual), which is O(n²) per tag and synchronous. On 73 profiles (103 MB) convert took 247 s with the event loop blocked throughout; with this change it takes about 8 s, output byte-identical.SetofstableKey(entry)(JSON with sorted object keys;undefinedencoded distinctly) replaces the linearisDeepStrictEqualscan.isDeepStrictEqualignores key order, so sorting keys keeps the same equality.custom/description/loginHours/userLicenseafter the first still throwserror_profile_singleton_conflict).Tests to add: single-file profile with a repeated entry converts unchanged; two pieces sharing an entry merge with it once; two pieces with different
<custom>still throw.Report (also filed as forcedotcom/cli#3681)
Versions: @salesforce/source-deploy-retrieve 13.10.1 (same
mergeProfilesloop since 13.8.3, whenProfileMetadataFinalizerwas added; 13.8.2 and earlier copied profile files as-is). Node 26.0.0, macOS.Repro: a project with 73 profiles in one package directory (103 MB of
*.profile-meta.xml, largefieldPermissions/objectPermissionslists).ComponentSet.fromSource(profilesDir)thennew MetadataConverter().convert(cs, 'metadata', { type: 'zip' }):Output is byte-identical in all three (per-entry sha256 of the zip match).
Root cause:
src/convert/convertContext/profileMetadataFinalizer.ts,mergeProfiles, line 235:Every entry is compared with every entry already merged for that tag, synchronously, so a tag with n entries costs n²/2
isDeepStrictEqualcalls. This runs even when a profile has only one source file, where there is nothing to merge.Proposed fix: (1) when
profiles.length === 1, return the single profile's entries as-is (root attributes built the same way); (2) for several pieces, dedupe with aSetkeyed by a deterministic serialization of each entry (sorted object keys) instead of the linear scan. The singleton-conflict check is unchanged.Behavior note: with (1), exact duplicate entries inside one profile file are kept, as in 13.8.2 and earlier; 13.8.3-13.10.1 drop them. Duplicates across pieces are still removed.
The remaining ~6 s block after the fix is fast-xml-parser parsing all profiles back to back in
parseXml(~4 s) plusJsToXml(~1.3 s), from the finalizer parsing and re-serializing profiles that 13.8.2 streamed unchanged. Not addressed here.