diff --git a/.jules/bolt.md b/.jules/bolt.md index 7d3c603f..3b7ea5e9 100644 --- a/.jules/bolt.md +++ b/.jules/bolt.md @@ -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) 오버헤드를 방지해야 합니다. +## 2023-10-24 - Explicit Factor Level Optimization +**Learning:** Using `as.factor(c(rep('A', n), rep('B', m)))` causes R to dynamically allocate a string array and perform O(N) operations to infer levels alphabetically. +**Action:** When grouping factors with known values, always bypass automatic factor level inference overhead by explicitly defining levels, e.g., `factor(rep(c('A', 'B'), c(n, m)), levels = c('A', 'B'))`. diff --git a/R/aFIPC.R b/R/aFIPC.R index 62546519..77baa444 100644 --- a/R/aFIPC.R +++ b/R/aFIPC.R @@ -612,11 +612,11 @@ autoFIPC <- #IPD if (checkIPD == T) { # config - IPDgroup <- - as.factor(c( - rep('oldForm', nrow(oldformYDataK)), - rep('newForm', nrow(newformXDataK)) - )) + # ⚡ Bolt: Bypass O(N) factor level inference and dynamic string array allocation + IPDgroup <- factor( + rep(c('oldForm', 'newForm'), c(nrow(oldformYDataK), nrow(newformXDataK))), + levels = c('newForm', 'oldForm') + ) IPDItemCount <- 0 # IPD target item checking