-
Notifications
You must be signed in to change notification settings - Fork 0
⚡ Bolt: 팩터 생성 시 자동 레벨 추론 오버헤드 최적화 #304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) 오버헤드를 방지해야 합니다. | ||
| ## 2025-02-13 - R 언어에서 factor 생성시 자동 레벨 추론 오버헤드 최적화 | ||
| **Learning:** R에서 팩터를 생성할 때 as.factor()를 사용하면 데이터에 포함된 전체 값들의 유니크한 레벨을 자동으로 스캔하고 정렬하는 과정이 발생합니다. 특히 반복된 값들을 이어붙일 때 as.factor()를 쓰면 O(N)의 스캔 오버헤드가 큽니다. | ||
| **Action:** rep()를 사용해 값들을 반복 생성할 때 factor() 함수에 명시적으로 `levels`를 지정하면, 자동 레벨 추론 및 정렬 오버헤드를 건너뛰어 O(1) 수준으로 매우 빠르게 팩터를 생성할 수 있습니다. 단, 원본 팩터 레벨 순서에 맞게 정확하게 지정해야 합니다. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: printf '%s\n' '--- applicable repository guidance ---'
find /tmp/coderabbit-repo-knowledge/contextualwisdomlab-afipc-649c8ab4/contextualwisdomlab-afipc-649c8ab4 -type f -name '*.md' -print 2>/dev/null | sort
find /tmp/coderabbit-repo-knowledge/contextualwisdomlab-afipc-649c8ab4/learnings -type f -name '*.md' -print 2>/dev/null | sort
printf '%s\n' '--- target document ---'
cat -n .jules/bolt.mdRepository: ContextualWisdomLab/aFIPC Length of output: 3344 🏁 Script executed: printf '%s\n' '--- R version declarations ---'
git ls-files | rg '(^|/)(DESCRIPTION|renv\.lock|Dockerfile[^/]*|.*\.yml|.*\.yaml|.*\.Rproj)$' | sort
rg -n -i 'R[_ -]?version|r-base|rocker/|setup-r|r-version|R_VERSION' --glob '!*.md' --glob '!*.lock' . 2>/dev/null | head -100
printf '%s\n' '--- target context ---'
sed -n '16,23p' .jules/bolt.mdRepository: ContextualWisdomLab/aFIPC Length of output: 18103 🌐 Web query:
💡 Result: In R, the base factor function constructs a factor object, which internally stores data as an integer vector with a "levels" attribute [1][2]. The relationship between explicit levels and the source data is managed through the levels and labels arguments [3][4]. 1. Levels Argument: When you provide an explicit levels argument, you define the set of valid values for the factor [4]. If a value in the input vector x does not match any entry in levels, R assigns NA to that position [3][5]. This is distinct from the default behavior, where unique(x) is used to determine levels [2]. 2. Labels Argument: The labels argument provides human-readable display names for those levels [4]. By default, labels are equal to levels [1][6]. If you provide labels, they must have the same length as the (post-exclusion) levels [2][4]. R maps the input vector to the specified levels and then applies the labels as the "levels" attribute of the resulting object [2]. 3. Complexity and Matching: Internally, factor uses match(x, levels) to find the integer codes corresponding to the input [2]. This process is case-sensitive and literal. If labels are provided, they are assigned to the levels attribute of the factor, effectively replacing the original level names in the output [2][7]. In essence, levels define the "validity" and "ordering" of the input data, while labels define the "representation" of those levels in the final object [7][4]. Using explicit levels is common practice to ensure all categories are represented, even if they are missing from a subset of data [4][8]. Citations:
팩터 생성 복잡도 설명을 수정하세요.
🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -612,11 +612,12 @@ autoFIPC <- | |
| #IPD | ||
| if (checkIPD == T) { | ||
| # config | ||
| # ⚡ Bolt: Optimize factor creation by avoiding automatic level inference overhead and using vectorized rep() | ||
| IPDgroup <- | ||
| as.factor(c( | ||
| rep('oldForm', nrow(oldformYDataK)), | ||
| rep('newForm', nrow(newformXDataK)) | ||
| )) | ||
| factor( | ||
| rep(c('oldForm', 'newForm'), c(nrow(oldformYDataK), nrow(newformXDataK))), | ||
| levels = c('newForm', 'oldForm') | ||
| ) | ||
|
Comment on lines
+617
to
+620
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| IPDItemCount <- 0 | ||
|
|
||
| # IPD target item checking | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔍 Constant-time claim is inaccurate
Explicit levels avoid discovery and sorting, but
rep()andfactor()still process every row. Factor creation remains O(N), not O(1).Was this helpful? React with 👍 or 👎 to provide feedback.