Skip to content

Pull Request: Optimize process_nested_dict and Data Copying Strategy - #1392

Closed
Polarskyk wants to merge 2 commits into
Guovin:masterfrom
Polarskyk:edit1
Closed

Polarskyk wants to merge 2 commits into
Guovin:masterfrom
Polarskyk:edit1

Conversation

@Polarskyk

Copy link
Copy Markdown

Overview
This PR improves the performance of URL deduplication and statistics in process_nested_dict and replaces heavy deepcopy with a lightweight shallow-copy approach, reducing unnecessary traversals and memory overhead.

Changes

  1. tools.py — Merge counting into process_nested_dict
    Before: The function performed deduplication and updated the dictionary, then separately called get_urls_len to traverse the entire data structure again to count the remaining URLs.

After: While iterating for deduplication, the function now accumulates the count of actually kept URLs and returns this total as an additional return value.

Benefit: Eliminates one full traversal, saving O(N) time—especially significant for large datasets.

  1. main.py — Replace deepcopy with lightweight shallow copy
    Before: copy.deepcopy was used to fully clone the nested dictionary, which is expensive.

After: Since process_nested_dict only replaces entire lists (data[key] = new_list) and never modifies inner dict objects, we now use a two‑level shallow copy to ensure isolation.

Removed: The unused import copy statement is deleted.

Benefit: Drastically reduces copying cost, lowering memory peak usage.

@github-actions github-actions Bot added the invalid This doesn't seem right label Aug 2, 2026
@github-actions github-actions Bot closed this Aug 2, 2026
@Polarskyk
Polarskyk deleted the edit1 branch August 7, 2026 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

invalid This doesn't seem right

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant