diff --git a/news/1152.feature b/news/1152.feature new file mode 100644 index 000000000..72aaff48c --- /dev/null +++ b/news/1152.feature @@ -0,0 +1 @@ +The YAML dumper will now use `yaml.CDumper` instead of `yaml.Dumper` whenever possible to speed up dumping diff --git a/omegaconf/_utils.py b/omegaconf/_utils.py index ec07aa51f..2575f0452 100644 --- a/omegaconf/_utils.py +++ b/omegaconf/_utils.py @@ -41,6 +41,13 @@ except ImportError: # pragma: no cover BaseLoader = yaml.SafeLoader +try: + from yaml import CDumper + + BaseDumper = CDumper +except ImportError: # pragma: no cover + BaseDumper = yaml.Dumper + NoneType: Type[None] = type(None) BUILTIN_VALUE_TYPES: Tuple[Type[Any], ...] = ( @@ -105,7 +112,7 @@ def __repr__(self) -> str: _DEFAULT_MARKER_: Any = Marker("_DEFAULT_MARKER_") -class OmegaConfDumper(yaml.Dumper): # type: ignore +class OmegaConfDumper(BaseDumper): # type: ignore str_representer_added = False @staticmethod