Skip to content
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

feat: add disable_limit_max_threads feature and limit the max threads to 2 by default for CRAN compatibility #720

Merged
merged 12 commits into from
Jan 26, 2024

Conversation

eitsupi
Copy link
Collaborator

@eitsupi eitsupi commented Jan 20, 2024

Close #241

@eitsupi eitsupi added this to the 1st CRAN Release milestone Jan 20, 2024
@eitsupi eitsupi marked this pull request as ready for review January 20, 2024 09:07
R/zzz.R Outdated
# Auto limit the max number of threads used by polars
if (
!(cargo_rpolars_feature_info()[["disable_auto_limit_max_threads"]] ||
isTRUE(getOption("polars.disable_auto_limit_max_threads"))) &&
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Related to #713, here disable_auto_limit_max_threads must be set via the options function.
Functions in the package polars are not useful here, since the value must be set when Polars is invoked.

@eitsupi
Copy link
Collaborator Author

eitsupi commented Jan 22, 2024

@etiennebacher Could you take a look at this?

NEWS.md Outdated Show resolved Hide resolved
NEWS.md Show resolved Hide resolved
NEWS.md Outdated Show resolved Hide resolved
R/info.R Outdated Show resolved Hide resolved
vignettes/install.Rmd Outdated Show resolved Hide resolved
@@ -23,5 +24,5 @@
- strictly_immutable: input must be TRUE or FALSE.
- debug_polars: input must be TRUE or FALSE.

More info at `?polars_options`.
More info at `?polars::polars_options`.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Note: This is not directly related to this PR, but it is necessary to be able to display the help page without loading the package because the package cannot be loaded if the option validation fails.

@etiennebacher
Copy link
Collaborator

Just fyi I'll try to do another review tomorrow or friday, very busy week

Copy link
Collaborator

@etiennebacher etiennebacher left a comment

Choose a reason for hiding this comment

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

The changes look good but I still have comments about the feature names and a few minor ones

R/info.R Outdated Show resolved Hide resolved
R/options.R Outdated
@@ -179,6 +175,7 @@ polars_options = function() {
df_knitr_print = getOption("polars.df_knitr_print"),
do_not_repeat_call = getOption("polars.do_not_repeat_call"),
int64_conversion = getOption("polars.int64_conversion"),
limit_max_threads = getOption("polars.limit_max_threads") %||% "Not set (NULL)",
Copy link
Collaborator

Choose a reason for hiding this comment

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

if the default is to limit the number of threads to 2, shouldn't it be %||% TRUE?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

TRUE doesn't make sense. This is because there is a possibility that the behavior will be changed on the lib side. Only an explicit FALSE is meaningful

Copy link
Collaborator

@etiennebacher etiennebacher Jan 25, 2024

Choose a reason for hiding this comment

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

Sorry I don't understand that. Suppose I install the package and I don't change any option. This means that there is an automatic limit to use 2 threads. If I do polars_options(), what would be printed?

limit_max_threads TRUE or limit_max_threads Not set (NULL)?

If it's TRUE, I think it's fine, but if it's Not set (NULL) then that's confusing because I would understand it as "there's no limit in the number of threads", while actually there is one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The default is changed to !polars_info()$features$disable_limit_max_threads

R/options.R Outdated Show resolved Hide resolved
R/utils.R Outdated Show resolved Hide resolved
R/zzz.R Show resolved Hide resolved
src/rust/Cargo.toml Outdated Show resolved Hide resolved
@eitsupi eitsupi changed the title feat: add disable_auto_limit_max_threads feature feat: add disable_limit_max_threads feature and Jan 26, 2024
@eitsupi eitsupi changed the title feat: add disable_limit_max_threads feature and feat: add disable_limit_max_threads feature and limit the max threads to 2 by default for CRAN compatibility Jan 26, 2024
Copy link
Collaborator

@etiennebacher etiennebacher left a comment

Choose a reason for hiding this comment

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

Thanks, this looks good to me, sorry for the delay

@eitsupi
Copy link
Collaborator Author

eitsupi commented Jan 26, 2024

Thanks for your detailed review!

@eitsupi eitsupi merged commit 919c93c into main Jan 26, 2024
31 checks passed
@eitsupi eitsupi deleted the auto-limit-threads branch January 26, 2024 22:21
@@ -77,10 +81,22 @@ check_feature = function(feature_name, context = NULL, call = sys.call(1L)) {
#'
#' The threadpool size can be overridden by setting the
#' `POLARS_MAX_THREADS` environment variable before process start.
#' (The thread pool is not behind a lock, so it cannot be modified once set).
#' It cannot be modified once `polars` is loaded.
Copy link

Choose a reason for hiding this comment

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

thank you for documenting this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

how to config max number of threads?
3 participants