-
-
Notifications
You must be signed in to change notification settings - Fork 46
test: add failing test for large dataset performance (#420) #421
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
ANAMASGARD
wants to merge
6
commits into
easystats:main
Choose a base branch
from
ANAMASGARD:perf/issue-420-large-dataset-sampling
base: main
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 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3526585
test: add failing test for large dataset performance (#420)
ANAMASGARD 4f93079
refactor: address code review suggestions
ANAMASGARD d7e9621
perf: sample large datasets in check_model plots (#420)
ANAMASGARD c513591
style: fix linting issues in performance fix
ANAMASGARD efe3985
Merge branch 'main' into perf/issue-420-large-dataset-sampling
strengejacke 3dbbae1
Merge branch 'main' into perf/issue-420-large-dataset-sampling
ANAMASGARD 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| # ============================================================================== | ||
| # ISSUE #420: check_model() performance degradation with large datasets | ||
| # ============================================================================== | ||
| # | ||
| # This test documents the performance issue where check_model() becomes | ||
| # unusably slow (5+ minutes) with datasets >10K observations. | ||
| # | ||
| # The test verifies that plotting completes in reasonable time (<30 seconds) | ||
| # for large datasets. | ||
| # | ||
| # See: https://github.com/easystats/see/issues/420 | ||
| # ============================================================================== | ||
|
|
||
| test_that("check_model() handles large datasets efficiently", { | ||
| skip_if_not_installed("performance") | ||
| skip_if_not_installed("lme4") | ||
| skip_on_cran() # Large dataset test | ||
|
|
||
| # Create large dataset (25,000 observations) | ||
| set.seed(123) | ||
| large_data <- data.frame( | ||
| subject = rep(1:500, each = 50), | ||
| x = rnorm(25000), | ||
| y = rnorm(25000) | ||
| ) | ||
|
|
||
| # Fit model | ||
| model <- lme4::lmer(y ~ x + (1 | subject), data = large_data) | ||
|
|
||
| # check_model() should complete in reasonable time (<30 seconds) | ||
| # Currently this FAILS (takes 5+ minutes) | ||
| timing <- system.time({ | ||
| result <- performance::check_model(model) | ||
| # Force plot rendering to measure true performance | ||
| plot_result <- plot(result) | ||
| }) | ||
|
|
||
| # Test passes if under 30 seconds | ||
| expect_true(timing["elapsed"] < 30, | ||
| info = sprintf("check_model() took %.1f seconds (should be <30)", timing["elapsed"]) | ||
| ) | ||
|
|
||
| # Result should be valid | ||
| expect_s3_class(result, "check_model") | ||
| }) | ||
|
|
||
| test_that("data sampling preserves visual fidelity", { | ||
| skip_if_not_installed("performance") | ||
| skip_if_not_installed("lme4") | ||
|
|
||
| # Small dataset should not be sampled | ||
| small_data <- data.frame( | ||
| x = rnorm(100), | ||
| y = rnorm(100) | ||
| ) | ||
| model_small <- lm(y ~ x, data = small_data) | ||
|
|
||
| # Should complete quickly regardless | ||
| expect_no_error({ | ||
| result <- performance::check_model(model_small) | ||
| plot(result) | ||
| }) | ||
| }) | ||
|
|
||
| test_that("large dataset plot components use sampling", { | ||
| skip_if_not_installed("performance") | ||
| skip_on_cran() | ||
|
|
||
| # Create dataset with 15,000 observations (above threshold) | ||
| set.seed(456) | ||
| large_data <- data.frame( | ||
| x = rnorm(15000), | ||
| y = rnorm(15000) + 0.5 * rnorm(15000) | ||
| ) | ||
|
|
||
| model <- lm(y ~ x, data = large_data) | ||
ANAMASGARD marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # Check that plotting completes quickly | ||
| timing <- system.time({ | ||
| result <- performance::check_model(model) | ||
| plot_result <- plot(result) | ||
| }) | ||
|
|
||
| # Should be much faster with sampling | ||
| expect_true(timing["elapsed"] < 15, | ||
| info = sprintf("Plotting took %.1f seconds (should be <15 with sampling)", timing["elapsed"]) | ||
| ) | ||
| }) | ||
|
|
||
| test_that("medium datasets complete in reasonable time", { | ||
| skip_if_not_installed("performance") | ||
| skip_on_cran() | ||
|
|
||
| # Medium dataset (8,000 observations - below threshold) | ||
| set.seed(789) | ||
| medium_data <- data.frame( | ||
| x = rnorm(8000), | ||
| y = rnorm(8000) + rnorm(8000) | ||
| ) | ||
|
|
||
| model <- lm(y ~ x, data = medium_data) | ||
|
|
||
| # Should complete in reasonable time even without sampling | ||
| timing <- system.time({ | ||
| result <- performance::check_model(model) | ||
| plot_result <- plot(result) | ||
| }) | ||
|
|
||
| # Medium datasets should still be reasonably fast | ||
| expect_true(timing["elapsed"] < 20, | ||
| info = sprintf("Medium dataset plotting took %.1f seconds", timing["elapsed"]) | ||
| ) | ||
| }) | ||
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.
Uh oh!
There was an error while loading. Please reload this page.