Repository navigation
⚡ Bolt: 차트 내보내기(chart.py)의 중복 제거 로직 O(N^2)에서 O(N)으로 최적화 #849
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 22 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
40dcbc9
perf: 차트 내보내기에서 배열 조회(not in list)를 딕셔너리 키 조회로 변경하여 O(N^2) 성능 저하 방지
seonghobae 599c353
perf: 차트 내보내기에서 배열 조회(not in list)를 딕셔너리 키 조회로 변경하여 O(N^2) 성능 저하 방지
seonghobae 39a9265
build(security): update pdfjs-dist to 6.2.108 to resolve CVE-2026-16633
seonghobae 53e054c
build(security): update pdfjs-dist to 6.2.108 to resolve CVE-2026-16633
seonghobae 36db87e
chore(perf): isolate chart dedup optimization
seonghobae 2d92b26
perf: 차트 내보내기에서 배열 조회(not in list)를 딕셔너리 키 조회로 변경하여 O(N^2) 성능 저하 방지
seonghobae 9f58b96
perf: 차트 내보내기에서 배열 조회(not in list)를 딕셔너리 키 조회로 변경하여 O(N^2) 성능 저하 방지
seonghobae 86ccbf2
chore(perf): keep chart optimization dependency-neutral
seonghobae 5fc5e99
perf: 차트 내보내기에서 배열 조회(not in list)를 딕셔너리 키 조회로 변경하여 O(N^2) 성능 저하 방지
seonghobae 70893b7
perf(exports): restore chart deduplication to atomic scope
seonghobae 982a367
perf: 차트 내보내기에서 배열 조회(not in list)를 딕셔너리 키 조회로 변경하여 O(N^2) 성능 저하 방지
seonghobae f357941
chore(scope): restore chart optimization isolation
seonghobae 45a3020
perf: 차트 내보내기에서 배열 조회(not in list)를 딕셔너리 키 조회로 변경하여 O(N^2) 성능 저하 방지
seonghobae 1a3d674
test(chart): keep optimization notes in Unreleased
seonghobae 88aa81b
fix(changelog): keep chart optimization unreleased
seonghobae fe7c49d
test(changelog): freeze released audio-intake history
seonghobae ee9d0d4
fix(changelog): restore immutable released wording
seonghobae e0f87a9
perf: 차트 내보내기에서 배열 조회(not in list)를 딕셔너리 키 조회로 변경하여 O(N^2) 성능 저하 방지
seonghobae 26b6614
fix(chart): restore Unreleased changelog ownership
seonghobae 6073935
test(chart): restore ordered dedup regression contract
seonghobae 6674b56
test(chart): exercise distinct active duplicate roles
seonghobae e3268c8
test(chart): preserve linear dedup complexity contract
seonghobae f1d7067
Merge remote-tracking branch 'origin/develop' into HEAD
seonghobae 352d954
perf: 차트 내보내기에서 배열 조회(not in list)를 딕셔너리 키 조회로 변경하여 O(N^2) 성능 저하 방지
seonghobae 3b7717d
perf: 차트 내보내기에서 O(N^2) 성능 저하 방지 및 npm/Trivy CI 실패 수정
seonghobae a868964
Merge branch 'develop' into perf-chart-dedup-7079628762098570838
seonghobae 9c27a94
perf: 차트 내보내기에서 O(N^2) 성능 저하 방지
seonghobae File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
37 changes: 37 additions & 0 deletions
37
services/analysis-engine/tests/test_chart_export_dedup_complexity.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| """Deterministic complexity regression for chart-export role de-duplication.""" | ||
|
|
||
| from typing import ClassVar | ||
|
|
||
| from bandscope_analysis.exports.chart import _active_role_ids | ||
|
|
||
|
|
||
| class _CountingRoleId(str): | ||
| """String role id that counts equality work without wall-clock timing.""" | ||
|
|
||
| comparisons: ClassVar[int] = 0 | ||
|
|
||
| def __eq__(self, other: object) -> bool: | ||
| """Count one equality comparison and preserve normal string semantics.""" | ||
| type(self).comparisons += 1 | ||
| return super().__eq__(other) | ||
|
|
||
| def __hash__(self) -> int: | ||
| """Preserve normal string hashing for representative hash membership.""" | ||
| return super().__hash__() | ||
|
|
||
|
|
||
| def test_active_role_id_deduplication_avoids_quadratic_equality_work() -> None: | ||
| """Unique active ids must not require pairwise list-membership comparisons.""" | ||
| role_ids = [_CountingRoleId(f"role-{index}") for index in range(64)] | ||
| section = { | ||
| "partGraph": [ | ||
| {"role_id": role_id, "is_active": True} | ||
| for role_id in [*role_ids, _CountingRoleId("role-0")] | ||
| ] | ||
| } | ||
|
|
||
| _CountingRoleId.comparisons = 0 | ||
| active = _active_role_ids(section) | ||
|
|
||
| assert active == role_ids | ||
| assert _CountingRoleId.comparisons < 256 |
116 changes: 116 additions & 0 deletions
116
services/analysis-engine/tests/test_chart_export_optimization_contract.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| """Regression contracts for the ordered chart-export optimization.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| from bandscope_analysis.exports.chart import build_chart_text, build_cue_sheet_rows | ||
|
|
||
| PERFORMANCE_NOTE = ( | ||
| "- 차트 내보내기(chart.py)에서 `not in list` 대신 삽입 순서가 보장되는 " | ||
| "딕셔너리(`dict.keys()`)를 활용하여 역할, 큐 및 우선순위 데이터의 중복 제거 " | ||
| "방식을 $O(N^2)$에서 $O(N)$으로 최적화했습니다." | ||
| ) | ||
| RELEASED_AUDIO_INTAKE_NOTE = ( | ||
| "- Issue #33: Implemented secure local audio intake and project bootstrap" | ||
| ) | ||
|
|
||
|
|
||
| def _repo_root() -> Path: | ||
| """Return the repository root from this analysis-engine test module.""" | ||
| for parent in Path(__file__).resolve().parents: | ||
| if (parent / "CHANGELOG.md").is_file() and (parent / "package.json").is_file(): | ||
| return parent | ||
| raise RuntimeError("Could not locate the repository root") | ||
|
|
||
|
|
||
| def _role(role_id: str, name: str, priority: str) -> dict[str, object]: | ||
| """Build the minimal role payload used by the priority-order regression.""" | ||
| return {"id": role_id, "name": name, "rehearsalPriority": priority} | ||
|
|
||
|
|
||
| def _cue_role(role_id: str, name: str, cue_value: str) -> dict[str, object]: | ||
| """Build an active role with a display name and cue for ordered dedup tests.""" | ||
| return { | ||
| "id": role_id, | ||
| "name": name, | ||
| "cue": {"kind": "entrance", "value": cue_value}, | ||
| } | ||
|
|
||
|
|
||
| def test_chart_optimization_note_is_owned_by_unreleased() -> None: | ||
| """Keep current performance work out of immutable historical release notes.""" | ||
| changelog = (_repo_root() / "CHANGELOG.md").read_text(encoding="utf-8") | ||
| unreleased, separator, released = changelog.partition("\n## [0.1.3]") | ||
|
|
||
| assert separator, "expected the first released-version heading" | ||
| assert PERFORMANCE_NOTE in unreleased | ||
| assert changelog.count(PERFORMANCE_NOTE) == 1 | ||
| assert RELEASED_AUDIO_INTAKE_NOTE in released | ||
| assert "- Issue #33: Engineered secure local audio intake and project bootstrap" not in released | ||
|
|
||
|
|
||
| def test_priority_deduplication_preserves_first_occurrence_order_exactly() -> None: | ||
| """De-duplicate exact priority lines while retaining their source order.""" | ||
| song: dict[str, object] = { | ||
| "title": "Ordered priorities", | ||
| "sections": [ | ||
| { | ||
| "label": "verse", | ||
| "timeRange": {"start": 0, "end": 10}, | ||
| "roles": [ | ||
| _role("bass", "Bass", "high"), | ||
| _role("drums", "Drums", "medium"), | ||
| _role("bass-copy", "Bass", "high"), | ||
| ], | ||
| }, | ||
| { | ||
| "label": "chorus", | ||
| "timeRange": {"start": 10, "end": 20}, | ||
| "roles": [ | ||
| _role("keys", "Keys", "low"), | ||
| _role("drums-copy", "Drums", "medium"), | ||
| ], | ||
| }, | ||
| ], | ||
| } | ||
|
|
||
| output = build_chart_text(song) | ||
| priority_lines = [line for line in output.splitlines() if line.startswith(" - ")] | ||
|
|
||
| assert priority_lines == [ | ||
| " - Bass: high", | ||
| " - Drums: medium", | ||
| " - Keys: low", | ||
| ] | ||
|
|
||
|
|
||
| def test_active_role_and_cue_deduplication_uses_distinct_active_role_ids() -> None: | ||
| """Exercise duplicate display/cue values through distinct active graph role IDs.""" | ||
| song: dict[str, object] = { | ||
| "title": "Ordered active values", | ||
| "sections": [ | ||
| { | ||
| "label": "verse", | ||
| "timeRange": {"start": 0, "end": 10}, | ||
| "roles": [ | ||
| _cue_role("bass", "Bass", "Walk up"), | ||
| _cue_role("drums", "Drums", "Hit on 1"), | ||
| _cue_role("bass-copy", "Bass", "Walk up"), | ||
| _cue_role("drums-copy", "Drums", "Hit on 1"), | ||
| ], | ||
| "partGraph": [ | ||
| {"role_id": "bass", "is_active": True}, | ||
| {"role_id": "drums", "is_active": True}, | ||
| {"role_id": "bass-copy", "is_active": True}, | ||
| {"role_id": "drums-copy", "is_active": True}, | ||
| ], | ||
| } | ||
| ], | ||
| } | ||
|
|
||
| rows = build_cue_sheet_rows(song) | ||
|
|
||
| assert rows[0]["roles"] == ["Bass", "Drums"] | ||
| assert rows[0]["cue"] == "Walk up; Hit on 1" | ||
| assert "roles: Bass, Drums" in build_chart_text(song) |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 Info: chart.py dedup change preserves output
Replacing the
not in listchecks with insertion-ordered dict keys in_active_role_ids,_active_role_names,_section_cue, and_footer_lineskeeps first-occurrence order and identical dedup results, so the emitted lists and joined strings are unchanged while complexity drops to O(N).Was this helpful? React with 👍 or 👎 to provide feedback.