Skip to content

⚡ Vectorize chromagram variance calculation in chord recognizer - #244

Merged
seonghobae merged 8 commits into
developfrom
perf/chord-recognizer-vectorization-13733934016029207333
Jun 12, 2026
Merged

⚡ Vectorize chromagram variance calculation in chord recognizer#244
seonghobae merged 8 commits into
developfrom
perf/chord-recognizer-vectorization-13733934016029207333

Conversation

@seonghobae

Copy link
Copy Markdown
Collaborator

💡 What: Vectorized the variance calculation of the chromagram across the time axis (axis 0), which computes the variance once for all frames, replacing the unvectorized np.var(chromagram[:, i]) inside the audio frame loop.
🎯 Why: To avoid the redundant array slicing and function call overhead that was slowing down the chord recognition processing loop. Calculating this out-of-band across the array in numpy's C-implementation allows it to process extremely quickly compared to looping in Python.
📊 Measured Improvement: The loop segment benchmark showed execution time drop from ~5.27 seconds to ~0.28 seconds for a simulated 60s audio file over 100 runs. This is roughly an 18x performance boost in the iteration section of chord recognition. The full functionality exactly matches previous behaviors and all tests pass cleanly.


PR created automatically by Jules for task 13733934016029207333 started by @seonghobae

@google-labs-jules

Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 685bac6b-fefb-481e-8150-c98e7f1e3ab8

📥 Commits

Reviewing files that changed from the base of the PR and between 4232bb8 and 0ffdf3a.

📒 Files selected for processing (1)
  • services/analysis-engine/src/bandscope_analysis/chords/chord_recognizer.py

📝 Walkthrough

Summary by CodeRabbit

릴리스 노트

  • 성능 최적화
    • 코드 호출 반복을 제거하여 음성 분석 성능을 개선했습니다.

둘러보기

Chord recognizer의 프레임 처리 루프에서 chroma 분산 계산을 반복으로 수행하던 방식을 변경했습니다. 루프 진입 전 np.var(chromagram, axis=0)로 모든 프레임의 분산을 한 번에 계산하여 저장하고, 루프 내부에서는 사전 계산된 값을 참조하도록 최적화했습니다.

변경 사항

Chroma 분산 계산 최적화

계층 / 파일 설명
Chroma 분산 사전 계산 및 참조
services/analysis-engine/src/bandscope_analysis/chords/chord_recognizer.py
루프 진입 전에 np.var(chromagram, axis=0)로 프레임별 분산을 한 번만 계산하여 chroma_vars에 저장하고, 루프 내부에서 chroma_vars[i]로 참조하여 프레임 반복 계산을 제거했습니다.

예상 코드 리뷰 난이도

🎯 1 (매우 간단함) | ⏱️ ~3분

관련 PR

  • Seongho-Bae/bandscope#272: 두 PR 모두 ChordRecognizer의 chord_recognizer.py를 수정합니다. 이 PR은 chroma 분산 계산 방식을 최적화하고, 관련 PR은 노이즈/침묵 판정에 사용되는 분산 값을 참조하는 segment 생성 흐름을 리팩터링합니다.

제안 레이블

codex

🐰 체인지로그 축하시

Chroma 분산을 한 번만 계산하고
루프는 저장된 값을 재밌게 참조하네!
반복 계산 제거해
더 빠르고 깔끔한 코드,
효율의 승리입니다! 🎵✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed 제목은 PR의 주요 변경사항인 chromagram 분산 계산 벡터화를 명확하고 간결하게 요약하고 있습니다.
Description check ✅ Passed 설명은 변경사항의 내용(벡터화), 이유(성능 개선), 측정된 개선사항(18배 성능 향상)을 구체적으로 다루고 있어 변경 내용과 관련이 있습니다.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 100.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf/chord-recognizer-vectorization-13733934016029207333
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch perf/chord-recognizer-vectorization-13733934016029207333

Warning

Billing warning: we have not been able to collect payment for this subscription for more than 72 hours. Please update the payment method or pay any pending invoices in Billing to avoid service interruption.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@seonghobae
seonghobae enabled auto-merge June 10, 2026 14:05
@seonghobae

Copy link
Copy Markdown
Collaborator Author

@coderabbitai resolve

@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Rate Limit Exceeded

@seonghobae have exceeded the limit for the number of chat messages per hour. Please wait 2 minutes and 40 seconds before sending another message.

@seonghobae

Copy link
Copy Markdown
Collaborator Author

@coderabbitai resolve

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jun 11, 2026
@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Comments resolved and changes approved.

@seonghobae

Copy link
Copy Markdown
Collaborator Author

Merged latest develop and narrowed this PR to the production chord recognizer vectorization only.

Validation:

  • uv run --project services/analysis-engine pytest services/analysis-engine/tests/test_chord_recognizer.py -q -> 10 passed.
  • (cd services/analysis-engine && uv run ruff check src tests) -> passed.

Cleanup:

  • Removed the standalone root benchmark.py artifact from the PR.
  • Final PR diff is only services/analysis-engine/src/bandscope_analysis/chords/chord_recognizer.py.

@coderabbitai approve

@coderabbitai coderabbitai Bot added the codex label Jun 12, 2026
@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

@seonghobae Looks great — clean, focused diff with passing tests and linting. Approving!

(∩^ω^)⊃━☆゚.*・。゚

✅ Action performed

Comments resolved and changes approved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant