Skip to content

[optimize] speed up diffKeys() with native Set intersection/difference semantics#34

Merged
TechQuery merged 6 commits into
masterfrom
copilot/speed-up-diffkeys-using-set-api
Jul 1, 2026
Merged

[optimize] speed up diffKeys() with native Set intersection/difference semantics#34
TechQuery merged 6 commits into
masterfrom
copilot/speed-up-diffkeys-using-set-api

Conversation

Copilot AI commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

PR-34 PR-34 PR-34 Powered by Pull Request Badge

diffKeys() previously built status maps via two array passes and per-item mutation. This update moves key comparison to set algebra, reducing duplicate work and aligning behavior with modern Set APIs.

  • Set-based key diff core

    • Reworked diffKeys() to compare oldList/newList via Set operations:
      • old \ newDiffStatus.Old
      • old ∩ newDiffStatus.Same
      • new \ oldDiffStatus.New
    • Keeps output shape unchanged (map + grouped entries).
  • Native latest-API usage

    • Uses Set.prototype.difference() and Set.prototype.intersection() directly (no built-in compatibility fallback).
  • Deterministic duplicate handling

    • Added focused coverage for duplicate keys to ensure duplicates are de-duplicated by set semantics and do not skew status classification.
const oldSet = new Set(oldList);
const newSet = new Set(newList);

for (const item of getSetDifference(oldSet, newSet)) map[item] = DiffStatus.Old;
for (const item of getSetIntersection(oldSet, newSet)) map[item] = DiffStatus.Same;
for (const item of getSetDifference(newSet, oldSet)) map[item] = DiffStatus.New;

Human changes

  1. [refactor] simplify methods with Base64 & Hex utility API of Uint8Array (53e4972)
  2. [migrate] upgrade to TypeScript 6, PNPM 11, Lint-Staged 17 & other latest Upstream packages/actions
  3. [optimize] simplify Copilot codes

Copilot AI linked an issue Jun 30, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Speed up diffKeys() with new Set() API Optimize diffKeys() with Set intersection/difference semantics Jun 30, 2026
Copilot AI requested a review from TechQuery June 30, 2026 20:09

@TechQuery TechQuery left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread source/data.ts Outdated

Copilot AI commented Jun 30, 2026

Copy link
Copy Markdown
Contributor Author

@copilot

已按评审意见改为直接使用最新 Set API,移除了兼容性 fallback。提交:5017736

Copilot AI changed the title Optimize diffKeys() with Set intersection/difference semantics Optimize diffKeys() with native Set intersection/difference semantics Jun 30, 2026
Copilot AI requested a review from TechQuery June 30, 2026 20:27
@TechQuery TechQuery marked this pull request as ready for review June 30, 2026 22:42
Copilot AI review requested due to automatic review settings June 30, 2026 22:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors diffKeys() to use set-based semantics for classifying keys as Old/Same/New, and adds a regression test to ensure duplicate keys don’t affect the classification results.

Changes:

  • Reworked diffKeys() to derive Old/Same/New sets from oldList and newList.
  • Added a unit test ensuring duplicate keys are ignored during comparison.
  • Bumped package version to 4.7.1.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
source/data.ts Refactors diffKeys() to compute key statuses using Set-based logic.
test/data.spec.ts Adds coverage to ensure duplicates do not skew diffKeys() results.
package.json Bumps the published package version.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread source/data.ts
@TechQuery TechQuery added the enhancement Some improvements label Jul 1, 2026
@TechQuery TechQuery changed the title Optimize diffKeys() with native Set intersection/difference semantics [optimize] speed up diffKeys() with native Set intersection/difference semantics Jul 1, 2026
@TechQuery TechQuery merged commit c8af6d3 into master Jul 1, 2026
1 check passed
@TechQuery TechQuery deleted the copilot/speed-up-diffkeys-using-set-api branch July 1, 2026 01:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Some improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

speed up diffKeys() with new Set() API

3 participants