Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@
## 2024-05-15 - [R Performance: ifelse Overhead]
**Learning:** In R, ifelse evaluates both true and false branches entirely before subsetting, which is very inefficient for vector operations.
**Action:** Optimize this by preallocating with res <- Y * 0 to preserve attributes and using vectorized subsetting like if any cond res subset <- ...
## 2024-11-20 - Optimize sapply overhead on lists with vapply
**Learning:** In R, `sapply()` involves significant overhead when inferring and simplifying the return type of a list operation. For large lists, this type-checking overhead is non-trivial.
**Action:** When the exact return type and structure of the list operation is known, replace `sapply(..., FUN)` with the optimized and type-safe `vapply(..., FUN, FUN.VALUE)`. For example, use `vapply(list, nrow, numeric(1))` instead of `sapply(list, nrow)` to enforce the return type and improve performance safely.
3 changes: 2 additions & 1 deletion R/llcont.R
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,8 @@ llcont.lavaan <- function(x, ...){
if(tolower(lavInspect(x, "options")$missing) == "ml.x") stop("cannot handle lavaan models with missing='ml.x'. consider using missing='ml'.", call. = FALSE)
mispatts <- lavInspect(x, "patterns")
if(any(class(mispatts) == "list")){
npatts <- max(sapply(mispatts, nrow))
## Bolt: replaced sapply(...) with type-safe vapply(..., numeric(1)) for performance
npatts <- max(vapply(mispatts, nrow, numeric(1)))
} else {
npatts <- nrow(mispatts)
}
Expand Down
48 changes: 0 additions & 48 deletions benchmark_hurdle_ifelse.R

This file was deleted.

Loading