Skip to content

⚡ Bolt: Optimize ifelse overhead in glm binomial likelihood calculations - #112

Open
seonghobae wants to merge 3 commits into
masterfrom
bolt-optimize-binomial-ifelse-15630168051741705681
Open

⚡ Bolt: Optimize ifelse overhead in glm binomial likelihood calculations#112
seonghobae wants to merge 3 commits into
masterfrom
bolt-optimize-binomial-ifelse-15630168051741705681

Conversation

@seonghobae

@seonghobae seonghobae commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

What

Replaced ifelse functions inside the binomial switch of R/llcont.R with direct mathematical operations and logical subsetting.

Why

In R, ifelse() evaluates both true and false branches entirely before subsetting, which is inefficient for vector operations and incurs significant overhead. This optimization removes the overhead while exactly preserving behavior (including handling of NAs, as mathematical subsetting behaves identically).

Impact

For calculating y, execution time is reduced by ~42% (mean execution dropped from ~70ms to ~42ms for N=1M). For calculating wt, execution time is reduced by ~73% (mean execution dropped from ~36ms to ~9.7ms for N=1M).

Measurement

Verified by running targeted benchmarks on y and wt calculations using microbenchmark with large inputs. Correctness verified by passing the full test suite.


PR created automatically by Jules for task 15630168051741705681 started by @seonghobae


Devin Review

Summary by CodeRabbit

  • 개선 사항
    • 이항 일반화 선형 모델의 계산 처리 성능을 개선했습니다.
    • 관측 수가 0이거나 유효하지 않은 가중치가 포함된 경우에도 기존과 동일한 결과가 유지됩니다.
    • 결측 조건을 안정적으로 처리해 모델 실행의 일관성을 높였습니다.

@google-labs-jules

Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai

coderabbitai Bot commented Aug 31, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 388ea81c-46fc-45d3-bbf9-d2fce8994df9

📥 Commits

Reviewing files that changed from the base of the PR and between 807e940 and c9c995b.

📒 Files selected for processing (1)
  • R/llcont.R

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

llcont.glm의 이항 분기에서 응답 비율과 가중치 비율 계산을 ifelse() 호출에서 벡터 계산과 논리적 부분집합 대입으로 변경했습니다. NA 조건은 FALSE로 처리합니다.

Changes

이항 GLM 비율 계산 최적화

Layer / File(s) Summary
비율 계산 및 조건부 대입
R/llcont.R
응답 비율은 n == 0인 위치를 0으로 설정합니다. 가중치 비율은 m <= 0인 위치를 0으로 설정합니다. 기존 출력 값을 유지합니다.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to c9c99

This localized optimization changes how binomial likelihood values are computed while preserving the existing behavior and improving performance; no actionable merge-blocking risk remains after normal checks and review.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 제목은 glm 이항 우도 계산에서 ifelse() 오버헤드를 최적화한다는 주요 변경 사항을 정확하고 간결하게 설명합니다.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0 files. (1 skipped: 1 unsupported.)

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bolt-optimize-binomial-ifelse-15630168051741705681

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Devin Review found 1 potential issue.

Devin Review

Comment thread R/llcont.R
Comment on lines +56 to +70
y_opt <- y[, 1]/n
cond_n <- n == 0
cond_n[is.na(cond_n)] <- FALSE
y_opt[cond_n] <- 0
y <- y_opt
} else {
n <- rep.int(1, length(y))
}
m <- if (any(n > 1)) n else wt
wt <- ifelse(m > 0, (wt/m), 0)
## Bolt: replaced ifelse with mathematical operations and logical subsetting for performance
wt_opt <- wt/m
cond_m <- m <= 0
cond_m[is.na(cond_m)] <- FALSE
wt_opt[cond_m] <- 0
wt <- wt_opt

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔍 Boundary equivalence lacks regression coverage

No test exercises y_opt with zero trials or wt_opt with zero weights. These boundaries drive the new overwrite logic.

Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant