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
7 changes: 7 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@
## 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 <- ...
## 2026-08-11 - [R Performance: ifelse vs Readability]
**Learning:** In R, replacing `ifelse()` with vectorized subsetting (and its required `NA` handling and scalar recycling) can severely degrade code readability, turning a 1-liner into 7 lines.
**Action:** Avoid this micro-optimization unless the specific `ifelse()` call is a proven, high-impact performance bottleneck.

## 2026-08-11 - [R Performance: vapply over sapply]
**Learning:** In R codebases, using `sapply` over a list involves significant overhead to deduce and simplify the return type.
**Action:** When the return type and length are known, prefer `vapply(..., FUN.VALUE = type)` over `sapply(...)` for better performance and safety.
2 changes: 1 addition & 1 deletion R/llcont.R
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ 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))
npatts <- max(vapply(mispatts, nrow, numeric(1)))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ“ Info: vapply FUN.VALUE coercion is safe

nrow returns an integer, which vapply(..., numeric(1)) coerces to double without error. max() on the result behaves identically to the prior sapply.

Open in Devin Review

Was this helpful? React with πŸ‘ or πŸ‘Ž to provide feedback.

} else {
npatts <- nrow(mispatts)
}
Expand Down
48 changes: 0 additions & 48 deletions benchmark_hurdle_ifelse.R

This file was deleted.

Loading