Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) 오버헤드를 방지해야 합니다.
## 2024-07-13 - R 언어에서 as.factor 추론 생략을 통한 요인(factor) 생성 최적화
**Learning:** `as.factor()` 함수는 문자열을 요인으로 변환할 때 내부적으로 모든 문자열을 알파벳 순으로 스캔하여 `levels`를 동적으로 추론합니다. 이는 O(N)의 비효율적인 스캔 및 복사 오버헤드를 유발합니다.
**Action:** `factor(..., levels = c(...))` 형태를 사용하여 요인의 값을 생성할 때 `levels`를 명시적으로 제공하여 알파벳 정렬 추론 과정을 우회해야 합니다. 이때 원본 데이터의 기본 알파벳 정렬 순서를 유지하여 기존 구조와 정확히 동일한 요인을 생성해야 버그를 방지할 수 있습니다.
10 changes: 5 additions & 5 deletions R/aFIPC.R
Original file line number Diff line number Diff line change
Expand Up @@ -612,11 +612,11 @@ autoFIPC <-
#IPD
if (checkIPD == T) {
# config
IPDgroup <-
as.factor(c(
rep('oldForm', nrow(oldformYDataK)),
rep('newForm', nrow(newformXDataK))
))
# ⚡ Bolt: By passing explicit factor levels matching default alphabetical sorting, we bypass the $O(N)$ factor level inference overhead
IPDgroup <- factor(
rep(c('oldForm', 'newForm'), c(nrow(oldformYDataK), nrow(newformXDataK))),
levels = c('newForm', 'oldForm')
)
Comment on lines +616 to +619

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Info: Factor refactor preserves value order and levels

rep(c('oldForm','newForm'), c(nOld,nNew)) reproduces the old concatenation order, and explicit levels = c('newForm','oldForm') matches as.factor's alphabetical sort. Integer codes and length are unchanged, so IPDData row alignment holds.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

IPDItemCount <- 0

# IPD target item checking
Expand Down
Loading