From 732d6c28fb5794366c7bf4841ea629bc34b4d91e Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Thu, 30 Jul 2026 19:42:20 +0000 Subject: [PATCH 1/4] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Optimize=20column=20nam?= =?UTF-8?q?e=20extraction=20avoiding=20O(N)=20memory=20copy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .jules/bolt.md | 3 +++ R/aFIPC.R | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.jules/bolt.md b/.jules/bolt.md index 7d3c603..de6d3cb 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) 오버헤드를 방지해야 합니다. +## 2024-07-31 - R 언어에서 불필요한 데이터 프레임의 부분 추출(subsetting) 방지를 통한 성능 최적화 +**Learning:** R에서 열 이름을 기반으로 공통 열을 찾기 위해 `colnames(df[cols])`를 사용하는 것은 데이터 프레임을 전체 스캔하고 부분집합을 추출하므로 O(N) 메모리 복사 및 계산 오버헤드가 발생합니다. +**Action:** `colnames(df[cols])` 대신 `intersect(cols, colnames(df))`를 사용하여 데이터를 복사하지 않고 인덱스만으로 효율적으로 공통 열을 찾음으로써 메모리 절약과 성능을 크게 향상시킬 수 있습니다. diff --git a/R/aFIPC.R b/R/aFIPC.R index 6254651..eb4474b 100644 --- a/R/aFIPC.R +++ b/R/aFIPC.R @@ -620,8 +620,8 @@ autoFIPC <- IPDItemCount <- 0 # IPD target item checking - newFormColNames <- colnames(newformXDataK[colnames(newFormModel@Data$data)]) - oldFormColNames <- colnames(oldformYDataK[colnames(oldFormModel@Data$data)]) + newFormColNames <- intersect(colnames(newFormModel@Data$data), colnames(newformXDataK)) + oldFormColNames <- intersect(colnames(oldFormModel@Data$data), colnames(oldformYDataK)) # ⚡ Bolt: Vectorized match() to avoid dynamic array growth overhead inside a for loop idxNew <- match(newformCommonItemNames, newFormColNames) @@ -749,8 +749,8 @@ autoFIPC <- } } - newFormColNames <- colnames(newformXDataK[colnames(newFormModel@Data$data)]) - oldFormColNames <- colnames(oldformYDataK[colnames(oldFormModel@Data$data)]) + newFormColNames <- intersect(colnames(newFormModel@Data$data), colnames(newformXDataK)) + oldFormColNames <- intersect(colnames(oldFormModel@Data$data), colnames(oldformYDataK)) # ⚡ Bolt: Cache parameter indices to avoid O(N) linear search inside loop newScaleParmsItemIdxCache <- split(seq_len(nrow(NewScaleParms)), NewScaleParms$item) From 9a26ac6dabb7590862bd7bfb738c2fcfb3eb6574 Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Thu, 30 Jul 2026 19:54:21 +0000 Subject: [PATCH 2/4] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Optimize=20column=20nam?= =?UTF-8?q?e=20extraction=20avoiding=20O(N)=20memory=20copy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .Rbuildignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.Rbuildignore b/.Rbuildignore index 232504f..0821274 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -22,3 +22,6 @@ ^\.jules(/.*)?$ ^\.trivyignore\.yaml$ ^trivy\.yaml$ +.semgrepignore +test_dummy.R +test_validation.R From f7a99c197ce64de04492bc034089eb4a4fb6744a Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Thu, 30 Jul 2026 20:28:09 +0000 Subject: [PATCH 3/4] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Optimize=20column=20nam?= =?UTF-8?q?e=20extraction=20avoiding=20O(N)=20memory=20copy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From 5d463015e638419f1442f5e76122cbf1e5c4a372 Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Fri, 31 Jul 2026 00:02:28 +0000 Subject: [PATCH 4/4] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Optimize=20column=20nam?= =?UTF-8?q?e=20extraction=20avoiding=20O(N)=20memory=20copy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit