Skip to content

⚡ Bolt: [성능 최적화] 리스트 중복 제거 로직 O(N^2) -> O(N) 개선#261

Open
seonghobae wants to merge 1 commit into
developfrom
bolt-optimize-list-deduplication-17172696501778822028
Open

⚡ Bolt: [성능 최적화] 리스트 중복 제거 로직 O(N^2) -> O(N) 개선#261
seonghobae wants to merge 1 commit into
developfrom
bolt-optimize-list-deduplication-17172696501778822028

Conversation

@seonghobae

Copy link
Copy Markdown
Contributor

💡 What: appguardrail_core/rules.py 파일의 extract_public_references_merge_references 함수에서 사용되던 O(N^2) 시간 복잡도를 가진 리스트 기반 중복 제거 로직을 dict.fromkeys()를 활용하여 O(N)으로 최적화했습니다.

🎯 Why: 기존의 if item not in list 방식은 리스트에 항목을 추가할 때마다 리스트 전체를 스캔해야 하므로 O(N^2)의 시간이 소요되어 성능 저하의 원인이 될 수 있습니다. 파이썬 3.7+부터 dict.fromkeys()는 순서를 보장하면서 해시 맵 조회를 통해 O(1) 시간 복잡도로 중복을 검사하므로 전체 작업을 O(N)으로 처리할 수 있어 훨씬 효율적입니다.

📊 Impact: SCAN_RULES 등에서 많은 양의 레퍼런스를 다룰 때 중복 제거 속도가 크게 향상됩니다. (시간 복잡도가 O(N^2)에서 O(N)으로 개선됨).

🔬 Measurement: 전체 테스트가 통과하는지 확인했으며, 기존 기능(참조 추출 및 병합 시 순서 유지)과 정확히 동일하게 동작함을 검증했습니다. (python -m pytest tests/ --cov=appguardrail_core --cov-report=term-missing 실행을 통해 커버리지 100% 유지 확인)


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

Replaces O(N^2) list iteration with O(N) dict.fromkeys() for order-preserving deduplication in appguardrail_core/rules.py.
@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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant