-
Notifications
You must be signed in to change notification settings - Fork 0
⚡ Bolt: 성능 향상 - 불필요한 메모리 복사 및 함수 오버헤드 제거 #310
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
Open
seonghobae
wants to merge
2
commits into
master
Choose a base branch
from
bolt-performance-optimization-intersect-sum-5501579247150265905
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -620,8 +620,9 @@ autoFIPC <- | |
| IPDItemCount <- 0 | ||
|
|
||
| # IPD target item checking | ||
| newFormColNames <- colnames(newformXDataK[colnames(newFormModel@Data$data)]) | ||
| oldFormColNames <- colnames(oldformYDataK[colnames(oldFormModel@Data$data)]) | ||
| # ⚡ Bolt: Use intersect to avoid O(N) memory copy caused by dataframe subsetting | ||
| 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 +750,9 @@ autoFIPC <- | |
| } | ||
| } | ||
|
|
||
| newFormColNames <- colnames(newformXDataK[colnames(newFormModel@Data$data)]) | ||
| oldFormColNames <- colnames(oldformYDataK[colnames(oldFormModel@Data$data)]) | ||
| # ⚡ Bolt: Use intersect to avoid O(N) memory copy caused by dataframe subsetting | ||
| 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) | ||
|
|
@@ -770,8 +772,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: Use sum(!is.na()) instead of length(stats::na.omit()) to avoid method dispatch and memory allocation overhead | ||
| (sum(!is.na(unique(newFormModel@Data$data[, newFormItemName]))) == | ||
| sum(!is.na(unique(oldFormModel@Data$data[, oldFormItemName])))) | ||
|
Comment on lines
+776
to
+777
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. |
||
| ) { | ||
| message( | ||
| 'applying ', | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: ContextualWisdomLab/aFIPC
Length of output: 208
🏁 Script executed:
Repository: ContextualWisdomLab/aFIPC
Length of output: 4779
🏁 Script executed:
Repository: ContextualWisdomLab/aFIPC
Length of output: 4756
🏁 Script executed:
Repository: ContextualWisdomLab/aFIPC
Length of output: 2629
🌐 Web query:
R official documentation data.frame character column subsetting undefined columns selected intersect character vectors💡 Result:
In R, when you attempt to subset a data frame using a character vector that contains names not present in the data frame's column names, R throws the error: "undefined columns selected" [1][2]. This occurs because the
[operator for data frames requires that every element in a character index vector corresponds to an existing column name [3][4]. To subset a data frame safely using a character vector without triggering this error, you should ensure that the subsetting vector only includes columns that actually exist in the data frame [2]. The most common and idiomatic way to achieve this is by using theintersect()function or the%in%operator to filter the character vector against the data frame's existing names [1][5]. Recommended approaches: 1. Using intersect: df[intersect(names(df), your_character_vector)] This returns only the columns that are present in both the data frame and your vector [1]. 2. Using the %in% operator: df[names(df) %in% your_character_vector] This identifies which existing column names are present in your vector and returns those columns [1][5]. Note: If you are subsetting a data frame with a single index (e.g.,df[my_vector]), R interprets the input as column indices [4][6]. If you accidentally pass a logical vector or a character vector containing non-existent names in this context, the "undefined columns selected" error is a common consequence [2]. Always ensure that when subsetting by columns, the indexing vector is either a valid subset of existing names or the correct logical mask [7][2].Citations:
🌐 Web query:
site:stat.ethz.ch/R-manual base intersect R documentation duplicates order💡 Result:
In R, the intersect function from the base package performs set intersection on two vectors [1]. Its behavior regarding duplicates and order is as follows: 1. Duplicates: The intersect function treats input vectors as mathematical sets by returning only unique values that are present in both input vectors [1]. Any duplicate elements present in the inputs are effectively removed in the resulting intersection [1]. 2. Order: The documentation does not explicitly guarantee a specific order of the elements in the output. However, practically, the function typically returns the unique elements in the order they appear in the first vector (x), restricted to those also found in the second vector (y) [2]. Technically, the base R implementation of intersect is built using value matching, internally similar to y[match(x, y, nomatch = 0)] but handled more carefully to ensure proper set-like behavior (unique results) [2][3]. Because it is designed for set operations, if you require the preservation of duplicates or specific handling of occurrence order, other methods such as using %in% or filtering with duplicated may be more appropriate depending on your specific needs [2][4][5].
Citations:
intersect()의 결과 차이를 문서화하세요.intersect(colnames(df), cols)는 누락된 이름과 중복을 제거하므로df[cols]와 항상 같은 결과를 보장하지 않습니다.df[cols]는 누락된 열에서"undefined columns selected"오류를 발생시킵니다. 스키마 불일치를 실패시켜야 하는 호출부에는 별도 존재성 검사를 사용하고, 누락을 허용하는 경우에만intersect()를 사용하도록 문서화하세요.🤖 Prompt for AI Agents