From 17c0dd2779dc3557e4da035c7bcaf6c104482abf Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Sat, 10 Oct 2026 22:19:29 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20=EA=B3=A0=EC=9C=A0=ED=95=9C?= =?UTF-8?q?=20NA=EA=B0=80=20=EC=95=84=EB=8B=8C=20=EA=B0=92=EC=9D=98=20?= =?UTF-8?q?=EA=B0=9C=EC=88=98=20=EA=B3=84=EC=82=B0=20=EC=B5=9C=EC=A0=81?= =?UTF-8?q?=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .jules/bolt.md | 4 ++++ R/aFIPC.R | 5 +++-- R/surveyFA.R | 3 ++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.jules/bolt.md b/.jules/bolt.md index 7d3c603f..7d87a004 100644 --- a/.jules/bolt.md +++ b/.jules/bolt.md @@ -16,3 +16,7 @@ ## 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-05-24 - Optimize unique non-NA value counting +**Learning:** Using `length(stats::na.omit(unique(x)))` or `length(unique(stats::na.omit(x)))` in R incurs significant overhead due to S3 method dispatch and attribute allocation from `na.omit`. +**Action:** Use the faster, vectorized logical approach `sum(!is.na(unique(x)))` to count unique non-NA values efficiently. diff --git a/R/aFIPC.R b/R/aFIPC.R index 62546519..5094f884 100644 --- a/R/aFIPC.R +++ b/R/aFIPC.R @@ -770,8 +770,9 @@ autoFIPC <- if ( !is.na(newFormItemName) && !is.na(oldFormItemName) && - (length(stats::na.omit(unique(newFormModel@Data$data[, newFormItemName]))) == - length(stats::na.omit(unique(oldFormModel@Data$data[, oldFormItemName])))) + # ⚡ Bolt: Replace length(stats::na.omit(unique())) with sum(!is.na(unique())) to avoid S3 method dispatch overhead + (sum(!is.na(unique(newFormModel@Data$data[, newFormItemName]))) == + sum(!is.na(unique(oldFormModel@Data$data[, oldFormItemName])))) ) { message( 'applying ', diff --git a/R/surveyFA.R b/R/surveyFA.R index f60fffd8..01331e7e 100644 --- a/R/surveyFA.R +++ b/R/surveyFA.R @@ -83,7 +83,8 @@ surveyFA <- function( response_data <- as.data.frame(data) response_data <- response_data[, vapply(response_data, function(column) { - nunique <- length(unique(stats::na.omit(column))) + # ⚡ Bolt: Replace length(unique(stats::na.omit())) with sum(!is.na(unique())) to avoid S3 method dispatch overhead + nunique <- sum(!is.na(unique(column))) nunique >= 2L }, logical(1L))]