diff --git a/.Rbuildignore b/.Rbuildignore index 232504f..388f1c6 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -22,3 +22,4 @@ ^\.jules(/.*)?$ ^\.trivyignore\.yaml$ ^trivy\.yaml$ +^\.semgrepignore$ diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml index e58bb33..9d4697b 100644 --- a/.github/workflows/code-quality.yml +++ b/.github/workflows/code-quality.yml @@ -37,8 +37,9 @@ jobs: ACTIONLINT_VERSION="1.7.10" ACTIONLINT_FILE="actionlint_${ACTIONLINT_VERSION}_linux_amd64.tar.gz" ACTIONLINT_BASE_URL="https://github.com/rhysd/actionlint/releases/download/v${ACTIONLINT_VERSION}" - curl -sSLo "$ACTIONLINT_FILE" "${ACTIONLINT_BASE_URL}/${ACTIONLINT_FILE}" - curl -sSLo actionlint_checksums.txt "${ACTIONLINT_BASE_URL}/actionlint_${ACTIONLINT_VERSION}_checksums.txt" + curl --retry 5 --retry-connrefused -sL -o "$ACTIONLINT_FILE" "${ACTIONLINT_BASE_URL}/${ACTIONLINT_FILE}" + curl --retry 5 -sL -o actionlint_checksums.txt \ + "${ACTIONLINT_BASE_URL}/actionlint_${ACTIONLINT_VERSION}_checksums.txt" grep "$ACTIONLINT_FILE" actionlint_checksums.txt | sha256sum -c - tar -xzf "$ACTIONLINT_FILE" actionlint chmod +x actionlint diff --git a/.github/workflows/security-audit.yml b/.github/workflows/security-audit.yml index b6e46e2..233aac1 100644 --- a/.github/workflows/security-audit.yml +++ b/.github/workflows/security-audit.yml @@ -25,8 +25,10 @@ jobs: - name: Install gitleaks run: | GITLEAKS_FILE="gitleaks_8.24.2_linux_x64.tar.gz" - curl -sSLo "$GITLEAKS_FILE" "https://github.com/gitleaks/gitleaks/releases/download/v8.24.2/$GITLEAKS_FILE" - curl -sSLo gitleaks_checksums.txt "https://github.com/gitleaks/gitleaks/releases/download/v8.24.2/gitleaks_8.24.2_checksums.txt" + curl --retry 5 --retry-connrefused -sL -o "$GITLEAKS_FILE" \ + "https://github.com/gitleaks/gitleaks/releases/download/v8.24.2/$GITLEAKS_FILE" + curl --retry 5 -sL -o gitleaks_checksums.txt \ + "https://github.com/gitleaks/gitleaks/releases/download/v8.24.2/gitleaks_8.24.2_checksums.txt" grep "$GITLEAKS_FILE" gitleaks_checksums.txt | sha256sum -c - tar -xzf "$GITLEAKS_FILE" gitleaks chmod +x gitleaks @@ -40,8 +42,9 @@ jobs: ACTIONLINT_VERSION="1.7.10" ACTIONLINT_FILE="actionlint_${ACTIONLINT_VERSION}_linux_amd64.tar.gz" ACTIONLINT_BASE_URL="https://github.com/rhysd/actionlint/releases/download/v${ACTIONLINT_VERSION}" - curl -sSLo "$ACTIONLINT_FILE" "${ACTIONLINT_BASE_URL}/${ACTIONLINT_FILE}" - curl -sSLo actionlint_checksums.txt "${ACTIONLINT_BASE_URL}/actionlint_${ACTIONLINT_VERSION}_checksums.txt" + curl --retry 5 --retry-connrefused -sL -o "$ACTIONLINT_FILE" "${ACTIONLINT_BASE_URL}/${ACTIONLINT_FILE}" + curl --retry 5 -sL -o actionlint_checksums.txt \ + "${ACTIONLINT_BASE_URL}/actionlint_${ACTIONLINT_VERSION}_checksums.txt" grep "$ACTIONLINT_FILE" actionlint_checksums.txt | sha256sum -c - tar -xzf "$ACTIONLINT_FILE" actionlint chmod +x actionlint diff --git a/.jules/bolt.md b/.jules/bolt.md index 7d3c603..38f8f10 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-20 - R 언어에서 데이터 프레임 값 할당 시 2D 서브셋팅 오버헤드 최적화 +**Learning:** R에서 데이터 프레임의 값을 수정할 때 `df[idx, "col"] <- val`와 같은 2D 서브셋팅 방식을 사용하면, `[<-.data.frame` 메소드 디스패치와 차원/팩터 레벨 검사 등 부가적인 오버헤드가 발생하여 성능이 크게 저하될 수 있습니다. (특히 반복문 내에서 심각함) +**Action:** `df$col[idx] <- val`와 같이 컬럼 벡터를 직접 참조하여 값을 할당하는 1D 백터 할당 방식을 사용하면, 내부적으로 리스트 접근(O(1))과 C-레벨 벡터 수정으로 처리되므로 속도가 훨씬 빨라집니다. diff --git a/R/aFIPC.R b/R/aFIPC.R index 6254651..22b7976 100644 --- a/R/aFIPC.R +++ b/R/aFIPC.R @@ -598,15 +598,15 @@ autoFIPC <- # Preserve mirt's structural estimability flags. Forcing every row TRUE # frees boundary parameters such as 2PL g/u and makes the Hessian unstable. - NewScaleParms[NewScaleParms$item == 'GROUP', "est"] <- FALSE - OldScaleParms[OldScaleParms$item == 'GROUP', "est"] <- FALSE + NewScaleParms$est[NewScaleParms$item == 'GROUP'] <- FALSE + OldScaleParms$est[OldScaleParms$item == 'GROUP'] <- FALSE - NewScaleParms[NewScaleParms$name == "COV_11", "est"] <- TRUE - OldScaleParms[OldScaleParms$name == "COV_11", "est"] <- TRUE + NewScaleParms$est[NewScaleParms$name == "COV_11"] <- TRUE + OldScaleParms$est[OldScaleParms$name == "COV_11"] <- TRUE if (itemtype == 'Rasch') { - NewScaleParms[NewScaleParms$name == "a1", "est"] <- FALSE - OldScaleParms[OldScaleParms$name == "a1", "est"] <- FALSE + NewScaleParms$est[NewScaleParms$name == "a1"] <- FALSE + OldScaleParms$est[OldScaleParms$name == "a1"] <- FALSE } #IPD @@ -786,14 +786,14 @@ autoFIPC <- oldIdx <- oldScaleParmsItemIdxCache[[oldFormItemStr]] # ⚡ Bolt: Remove unnecessary paste0() array string generation overhead - message(' Newform Parms: ', paste(NewScaleParms[newIdx, "value"], collapse = ' ')) - message(' Oldform Parms: ', paste(OldScaleParms[oldIdx, "value"], collapse = ' ')) + message(' Newform Parms: ', paste(NewScaleParms$value[newIdx], collapse = ' ')) + message(' Oldform Parms: ', paste(OldScaleParms$value[oldIdx], collapse = ' ')) - NewScaleParms[newIdx, "value"] <- - OldScaleParms[oldIdx, "value"] - message(' Linkedform Parms: ', paste(NewScaleParms[newIdx, "value"], collapse = ' '), '\n') + NewScaleParms$value[newIdx] <- + OldScaleParms$value[oldIdx] + message(' Linkedform Parms: ', paste(NewScaleParms$value[newIdx], collapse = ' '), '\n') - NewScaleParms[newIdx, "est"] <- + NewScaleParms$est[newIdx] <- FALSE } else { message( @@ -813,9 +813,9 @@ autoFIPC <- newBetaIdx <- NewScaleParms$item == 'BETA' oldBetaIdx <- OldScaleParms$item == 'BETA' - NewScaleParms[newBetaIdx, "value"] <- - OldScaleParms[oldBetaIdx, "value"] - NewScaleParms[newBetaIdx, "est"] <- + NewScaleParms$value[newBetaIdx] <- + OldScaleParms$value[oldBetaIdx] + NewScaleParms$est[newBetaIdx] <- FALSE message('applying BETA parameter as linking') @@ -823,7 +823,7 @@ autoFIPC <- message( ' Linkedform Parms: ', paste0( - NewScaleParms[newBetaIdx, "value"], + NewScaleParms$value[newBetaIdx], ' ' ), '\n' @@ -858,13 +858,13 @@ autoFIPC <- new_mean11_idx <- NewScaleParms$name == "MEAN_11" old_mean11_idx <- OldScaleParms$name == "MEAN_11" - NewScaleParms[new_cov11_idx, "est"] <- FALSE - OldScaleParms[old_cov11_idx, "est"] <- FALSE - NewScaleParms[new_mean11_idx, "est"] <- FALSE - OldScaleParms[old_mean11_idx, "est"] <- FALSE + NewScaleParms$est[new_cov11_idx] <- FALSE + OldScaleParms$est[old_cov11_idx] <- FALSE + NewScaleParms$est[new_mean11_idx] <- FALSE + OldScaleParms$est[old_mean11_idx] <- FALSE - NewScaleParms[new_cov11_idx, "value"] <- 1 - OldScaleParms[old_mean11_idx, "value"] <- 0 + NewScaleParms$value[new_cov11_idx] <- 1 + OldScaleParms$value[old_mean11_idx] <- 0 } if (freeMEAN == T) { LinkedModelSyntax <-