Skip to content
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@
^\.jules(/.*)?$
^\.trivyignore\.yaml$
^trivy\.yaml$
^\.semgrepignore$
^\.\.Rcheck$
^\.\.Rcheck/.*
Comment on lines +25 to +27
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@
## 2025-02-12 - R 언어에서 반복적인 mirt 모델 생성 시 불필요한 데이터프레임 부분집합 추출 최적화
**Learning:** R에서 데이터프레임의 특정 열을 추출하는 작업(`df[cols]`)은 O(N)의 메모리 복사를 수반합니다. `autoFIPC`에서 `mirt` 모델의 파라미터를 설정하거나 호출하는 과정 중에 `newformXDataK[colnames(newFormModel@Data$data)]` 코드가 반복해서 사용되었고, 심지어 `ncol()`을 위해 단순히 개수를 구할 때도 사용되어 불필요한 메모리 할당과 오버헤드를 초래했습니다.
**Action:** 조건문이나 반복문 내부에서 불필요하게 데이터프레임 부분집합 연산이 반복되지 않도록 외부에서 한 번만 `linkedFormData <- newformXDataK[colnames(newFormModel@Data$data)]`로 캐싱(caching)한 뒤, `ncol(linkedFormData)`와 `data = linkedFormData` 형태로 재사용하여 메모리 복사와 O(N) 오버헤드를 방지해야 합니다.
## 2025-02-13 - R 언어에서 정렬 기반 최소/최대값 탐색(sort) 최적화
**Learning:** R에서 최솟값 또는 최댓값을 찾기 위해 `sort(x)[1]`이나 `names(sort(x))[1]`을 사용하면 전체 배열을 정렬해야 하므로 O(N log N)의 오버헤드가 발생합니다.
**Action:** `sort()` 대신 `which.min(x)` 또는 `which.max(x)`를 사용하여 O(N) 선형 시간 복잡도로 성능을 최적화해야 합니다. (예: `names(sort(x))[1]` 대신 `names(which.min(x))`)
3 changes: 2 additions & 1 deletion R/surveyFA.R
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ surveyFA <- function(
names(p_values) <- rownames(fit_df)
if (any(!is.na(p_values))) {
p_values[is.na(p_values)] <- 1
candidate <- names(sort(p_values, decreasing = FALSE))[1L]
# ⚡ Bolt: Replace O(N log N) sort() with O(N) which.min()
candidate <- names(p_values)[which.min(p_values)]
if (!is.na(candidate) && p_values[[candidate]] < pThreshold) {
return(candidate)
}
Expand Down
Loading