Skip to content

⚡ Bolt: 최솟값 검색 성능 향상을 위한 O(N) 선형 탐색 적용#158

Open
seonghobae wants to merge 5 commits into
masterfrom
bolt/performance-sort-to-which-min-15804321789300926000
Open

⚡ Bolt: 최솟값 검색 성능 향상을 위한 O(N) 선형 탐색 적용#158
seonghobae wants to merge 5 commits into
masterfrom
bolt/performance-sort-to-which-min-15804321789300926000

Conversation

@seonghobae

Copy link
Copy Markdown
Collaborator

💡 What:

  • R/surveyFA.R에서 문항 제거 시 최소 p-value를 가진 문항을 찾기 위해 전체 p-value 벡터를 정렬하던 과정을(sort(p_values)[1L]) 최솟값을 바로 찾는 함수(which.min(p_values))로 교체했습니다.
  • 성능 최적화 교훈을 .jules/bolt.md 에 기록했습니다.

🎯 Why:

  • R에서 sort() 함수를 사용하면 O(N log N)의 시간 복잡도와 정렬 오버헤드가 발생합니다.
  • 단순히 최솟값 혹은 최댓값을 구하는 경우에는 which.min()/which.max()를 사용하여 O(N) 선형 탐색만 수행하는 것이 성능상 유리하며 불필요한 연산을 줄여 속도를 개선할 수 있습니다.

📊 Impact:

  • 불량 문항 탐지 과정에서 p-value 배열의 최솟값 탐색 속도가 기존 O(N log N) 정렬에서 O(N) 선형 탐색으로 최적화되어 문항 수가 많을수록 빠른 실행 속도를 보장합니다.

🔬 Measurement:

  • 테스트 스위트를 실행하여 Rscript -e "testthat::test_dir('tests/testthat')" 결과 기능 및 동작이 동일함을 확인했습니다. (기존 스킵된 mirt 패키지 의존 테스트 외 나머지 패스)

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

- p-value 정렬 과정에서 발생하는 O(N log N) 시간 복잡도를 O(N) 선형 탐색(which.min)으로 대체하여 성능 향상.
- 관련 학습 내용 .jules/bolt.md 에 기록.
@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.

Copilot AI review requested due to automatic review settings July 20, 2026 23:52
@seonghobae

Copy link
Copy Markdown
Collaborator Author

Validated and strengthened the current PR head (5c5f1c1):

  • added a package-level minimum-name helper with explicit empty/unnamed behavior;
  • preserved the original sorted-result semantics while keeping first-tie determinism;
  • added focused regression coverage (4 expectations);
  • full testthat::test_local(reporter = "summary"): pass;
  • R CMD build: pass;
  • R CMD check --no-manual --as-cran: 0 errors, 0 warnings, 3 pre-existing repository/package-structure NOTEs (New submission, .semgrepignore, and the existing top-level test_dummy.R/test_validation.R files).

CodeGraph was resynced after the edit and confirms the call path surveyFA -> select_bad_item -> .name_of_minimum.

- p-value 정렬 과정에서 발생하는 O(N log N) 시간 복잡도를 O(N) 선형 탐색(which.min)으로 대체하여 성능 향상.
- 관련 학습 내용 .jules/bolt.md 에 기록.

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

Note

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

surveyFA에서 문항 제거 로직 중 최소 p-value 후보를 찾는 부분을 정렬 기반(O(N log N))에서 선형 탐색(O(N))으로 최적화하고, 해당 성능 최적화 교훈을 문서로 남긴 PR입니다.

Changes:

  • sort(p_values)[1L] 기반 최소값 선택을 which.min() 기반으로 변경
  • 최적화 학습 내용을 .jules/bolt.md에 추가 기록

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
R/surveyFA.R 최소 p-value 후보 선택 로직을 정렬 대신 선형 탐색으로 변경
.jules/bolt.md 최솟값/최댓값 탐색 시 불필요한 정렬 제거에 대한 학습 기록 추가

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

Comment thread R/surveyFA.R
Comment thread .jules/bolt.md Outdated
Copilot AI review requested due to automatic review settings July 21, 2026 00:08
@seonghobae

Copy link
Copy Markdown
Collaborator Author

Current-head correction (76d99ae): intervening commit 427d394 removed the empty/unnamed-input guard and all minimum-selection regression tests. That reintroduced a length-zero condition hazard around names(which.min(...)).

This commit restores the guarded linear selector and its tests on top of the latest head.

  • focused minimum-selection tests: 4/4 pass;
  • CodeGraph confirms surveyFA -> select_bad_item -> .name_of_minimum;
  • restored source tree exactly matches fully validated tree 5c5f1c1;
  • that tree passed the full package tests, R CMD build, and R CMD check --no-manual --as-cran with 0 errors, 0 warnings, 3 pre-existing structure NOTEs.

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@google-labs-jules

Copy link
Copy Markdown

Current-head correction (76d99ae): intervening commit 427d394 removed the empty/unnamed-input guard and all minimum-selection regression tests. That reintroduced a length-zero condition hazard around names(which.min(...)).

This commit restores the guarded linear selector and its tests on top of the latest head.

  • focused minimum-selection tests: 4/4 pass;
  • CodeGraph confirms surveyFA -> select_bad_item -> .name_of_minimum;
  • restored source tree exactly matches fully validated tree 5c5f1c1;
  • that tree passed the full package tests, R CMD build, and R CMD check --no-manual --as-cran with 0 errors, 0 warnings, 3 pre-existing structure NOTEs.

Acknowledged.

Copilot AI review requested due to automatic review settings July 21, 2026 01:36
@seonghobae

Copy link
Copy Markdown
Collaborator Author

Current-HEAD repair evidence (01b5eee): corrected the new .jules/bolt.md entry date from 2024-07-21 to 2026-07-21 so it follows the prior 2025-02-12 entry chronologically. CodeGraph was initialized/explored and incrementally synced; git diff --check passed; the focused tests/testthat/test-minimum-selection.R regression test passed (4 expectations). The only prior unresolved review thread was replied to and resolved. The remaining names(which.min(v)) path was traced with CodeGraph and intentionally left unchanged because it is already O(N), has explicit empty-result handling, and is outside the sort-removal defect addressed by this PR.

@google-labs-jules

Copy link
Copy Markdown

Current-HEAD repair evidence (01b5eee): corrected the new .jules/bolt.md entry date from 2024-07-21 to 2026-07-21 so it follows the prior 2025-02-12 entry chronologically. CodeGraph was initialized/explored and incrementally synced; git diff --check passed; the focused tests/testthat/test-minimum-selection.R regression test passed (4 expectations). The only prior unresolved review thread was replied to and resolved. The remaining names(which.min(v)) path was traced with CodeGraph and intentionally left unchanged because it is already O(N), has explicit empty-result handling, and is outside the sort-removal defect addressed by this PR.

Acknowledged.

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

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

Comment thread R/surveyFA.R
Comment on lines +244 to 247
# Find the minimum in one pass instead of sorting every item-fit value.
candidate <- .name_of_minimum(p_values)
if (!is.na(candidate) && p_values[[candidate]] < pThreshold) {
return(candidate)
Comment on lines +10 to +17
test_that("minimum selection is deterministic for ties and empty inputs", {
expect_identical(
aFIPC:::.name_of_minimum(c(first = 0.1, second = 0.1)),
"first"
)
expect_true(is.na(aFIPC:::.name_of_minimum(numeric())))
expect_true(is.na(aFIPC:::.name_of_minimum(c(0.2, 0.1))))
})
Comment thread R/surveyFA.R
Comment on lines +1 to +8
.name_of_minimum <- function(values) {
minimum_index <- which.min(values)
value_names <- names(values)
if (length(minimum_index) != 1L || is.null(value_names)) {
return(NA_character_)
}
value_names[[minimum_index]]
}
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.

2 participants