Skip to content

[R-package] reduce cost of repeated parameter alias checks#5141

Merged
jameslamb merged 2 commits intomasterfrom
r/param-aliases
Apr 13, 2022
Merged

[R-package] reduce cost of repeated parameter alias checks#5141
jameslamb merged 2 commits intomasterfrom
r/param-aliases

Conversation

@jameslamb
Copy link
Collaborator

@jameslamb jameslamb commented Apr 11, 2022

Created in response to #5122 (comment).

For many of LightGBM's supported parameters (https://lightgbm.readthedocs.io/en/latest/Parameters.html), LightGBM respects multiple aliases. For example, num_iterations=10, nrounds=10, and num_tree=10 all result in the same behavior.

As a result of this, the R package frequently needs to deal with the possibility that some relevant configuration might be provided via any of these aliases, and sometimes via special keyword arguments in the R package's public API.

Earlier versions of {lightgbm} included a hard-coded list of string literals with a mapping from select "main" parameter names to their aliases. To ensure that the package is always in sync with changes on the C++ side, #4829 replaced that list with a call to an entrypoint in LightGBM's C++ code which returns a JSON string containing all parameters and their aliases.

As noted in #5122 (comment), each of those calls results in re-generating that JSON string and deserializing it into an R list.

Since the parameter mapping will never change within an R session, it should only be necessary to fetch it once. This PR proposes introducing an internal cache in the R package and changing .PARAMETER_ALIASES() to check that cache before going to the C++ side to get parameter aliases.

Copy link
Collaborator

@StrikerRUS StrikerRUS left a comment

Choose a reason for hiding this comment

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

Very nice indeed!

@jameslamb jameslamb merged commit 204fa9c into master Apr 13, 2022
@jameslamb jameslamb deleted the r/param-aliases branch April 13, 2022 02:29
@jameslamb jameslamb mentioned this pull request Oct 7, 2022
40 tasks
@github-actions
Copy link
Contributor

This pull request has been automatically locked since there has not been any recent activity since it was closed. To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants