perf: Replace `deepcopy` with Node-native `structuredClone` for faster object-cloning throughout the codebase
🔄 Replace deepcopy with Native structuredClone
✔️ Summary
This PR replaces all usages of the deepcopy package with the native structuredClone API.
It also removes the deepcopy dependency from package.json and package-lock.json.
🎯 Motivation
structuredCloneis now widely supported in Node.js and provides faster deep-copy operations.- Removing the external dependency reduces package size, maintenance overhead, and potential security risks.
- Ensures more consistent behavior by using a built-in native API.
🔍 Changes Included
- Replaced all
deepcopy(...)calls withstructuredClone(...) - Removed
deepcopyfrom dependency lists - Updated any related utility code to match the new cloning behavior
🧪 What to Review
- Verify that all object-cloning operations still behave as expected (especially nested objects, arrays, and edge cases).
- Confirm all tests pass and no regressions occur.
- Check for any remaining unused imports or references to
deepcopy.
Summary by CodeRabbit
- Refactor
- Removed the external
deepcopypackage dependency and replaced all cloning operations with the native JavaScriptstructuredClonemethod across the application, reducing external dependencies while maintaining equivalent functionality.
- Removed the external
✏️ Tip: You can customize this high-level summary in your review settings.
🚀 Thanks for opening this pull request!
📝 Walkthrough
Walkthrough
The pull request removes the external deepcopy dependency and replaces all usages with the native structuredClone() API across the codebase. This involves removing deepcopy from package.json and updating multiple modules in Controllers, GraphQL loaders, LiveQuery, Push services, and RestWrite to use structuredClone for object cloning operations.
Changes
| Cohort / File(s) | Summary |
|---|---|
Dependency Removal package.json |
Removed deepcopy from project dependencies |
Controllers src/Controllers/DatabaseController.js, src/Controllers/SchemaController.js |
Replaced deepcopy() calls with structuredClone() for cloning update payloads and classLevelPermissions; removed deepcopy imports |
GraphQL Loaders src/GraphQL/loaders/functionsMutations.js, src/GraphQL/loaders/parseClassMutations.js, src/GraphQL/loaders/parseClassQueries.js, src/GraphQL/loaders/schemaMutations.js, src/GraphQL/loaders/schemaQueries.js, src/GraphQL/loaders/usersMutations.js |
Replaced deepcopy(args) with structuredClone(args) across multiple mutateAndGetPayload handlers and query resolvers; removed deepcopy imports from all modules |
LiveQuery Service src/LiveQuery/ParseLiveQueryServer.ts |
Replaced deepcopy(parseObject) with structuredClone(parseObject) in subscription matching logic; removed deepcopy import |
Push Services src/Push/PushWorker.js, src/Push/utils.js |
Replaced deepcopy() calls with structuredClone() in push body/payload cloning operations within sendToAdapter and utility functions; removed deepcopy imports |
RestWrite src/RestWrite.js |
Replaced multiple deepcopy() calls with structuredClone() across constructor, data handling, and authData processing paths; removed deepcopy import |
Estimated code review effort
🎯 2 (Simple) | ⏱️ ~10 minutes
While affecting 13 files, the changes follow a consistent, repetitive pattern—direct substitution of deepcopy() with structuredClone() with no logic or control-flow modifications. However, reviewers should pay attention to:
- API compatibility: Verify that
structuredClone()handles all use cases identically todeepcopy(), particularly edge cases with nested objects, non-serializable properties (functions, symbols), and circular references - Object property handling: Confirm that any special object properties or prototype chains previously handled by
deepcopyare still properly cloned bystructuredClone() - RestWrite.js: The highest density of replacements; verify all cloning contexts (constructor, sanitizedData, buildParseObjects, authData flows) work correctly with the native API
Pre-merge checks and finishing touches
❌ Failed checks (1 warning, 1 inconclusive)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | ⚠️ Warning | Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. | You can run @coderabbitai generate docstrings to improve docstring coverage. |
| Description check | ❓ Inconclusive | The description includes a clear summary, motivation, detailed changes, and review guidance, but does not follow the required template structure with Issue and Approach sections. | Follow the repository's PR template by adding explicit 'Issue' (with link to related issue) and 'Approach' sections as specified in the template structure. |
✅ Passed checks (1 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title check | ✅ Passed | The title accurately summarizes the main objective: replacing the deepcopy dependency with Node-native structuredClone for performance improvements, which aligns perfectly with the changeset. |
✨ Finishing touches
- [ ] 📝 Generate docstrings
🧪 Generate unit tests (beta)
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
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.
Comment @coderabbitai help to get the list of available commands and usage tips.
:white_check_mark: Snyk checks have passed. No issues have been found so far.
| Status | Scanner | Total (0) | ||||
|---|---|---|---|---|---|---|
| :white_check_mark: | Open Source Security | 0 | 0 | 0 | 0 | 0 issues |
:computer: Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.
The CI fails consistently for these tests:
1) ParseGraphQLServer Auto API Schema Data Types should support files
- Failed: Cannot read properties of null (reading 'someClass')
2) ParseGraphQLServer Auto API Schema Data Types should support files on required file
- Failed: Cannot read properties of null (reading 'someClassWithRequiredFile')
3) ParseGraphQLServer Auto API Schema Data Types should support file upload for on fly creation through pointer and relation
- TypeError: Cannot read properties of null (reading 'someClass')
Since this is a perf improvement, this PR should add a perf benchmark as well. The current benchmark shows no significant improvement or degradation, which is a good sign so far. A dedicated test that shows improvement would be good, but if the perf change is insignificant that's also acceptable as we prefer native APIs over ext. dependencies.