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

Optimization: support unsafe_merge. #482

Closed
omry opened this issue Jan 21, 2021 · 0 comments · Fixed by #485
Closed

Optimization: support unsafe_merge. #482

omry opened this issue Jan 21, 2021 · 0 comments · Fixed by #485
Milestone

Comments

@omry
Copy link
Owner

omry commented Jan 21, 2021

Every config node in Hydra has a reference to the parent (needed for interpolation, among other things).
This means a config node cannot belong to two configs.
Hydra merge APIs do not change the input configs. This means that there is a deepcopy involved.

c1 = OmegaConf.create(...)
c2 = OmegaConf.create(...)
merged = OmegaConf.create(c1, c2)

In most cases, the input configs c1 and c2 above are discarded after the merge, which means the cost of the deepcopy is paid for no good reason.

    @staticmethod
    def unsafe_merge(
        *configs: Union[
            DictConfig,
            ListConfig,
            Dict[DictKeyType, Any],
            List[Any],
            Tuple[Any, ...],
            Any,
        ],
    ) -> Union[ListConfig, DictConfig]:
        """
        Merge a list of previously created configs into a single one
        This is much faster than OmegaConf.merge() as the input configs are not copied.
        However, the input configs must not be used after this operation as will become inconsistent.
        :param configs: Input configs
        :return: the merged config object.
        """
@omry omry added this to the OmegaConf 2.1 milestone Jan 21, 2021
@omry omry changed the title Optimization: support destructive merge. Optimization: support unsafe_merge. Jan 22, 2021
@omry omry mentioned this issue Jan 22, 2021
@omry omry closed this as completed in #485 Jan 22, 2021
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 a pull request may close this issue.

1 participant