How the experimental libfyaml backend works
masterPsych features an experimental, opt-in backend built on libfyaml. This backend targets YAML 1.2 compliance, whereas the default libyaml backend follows YAML 1.1.
Key Differences
- YAML 1.2 Semantics: In
libfyaml, YAML 1.1 booleans likeyes,no,on, andoffare loaded as plain strings instead oftrue/false. This resolves the "Norway problem" where the country codenowas parsed asfalse. - Performance:
libfyamlis competitive withlibyamlfor parsing but is significantly slower at emitting (roughly 1.7x to 1.9x slower). - Error Handling: On a parse error,
Psych::SyntaxError#problemcontains the fulllibfyamldiagnostic message, andPsych::SyntaxError#contextis alwaysnil. - Output Formatting: Byte-for-byte output parity with
libyamlis not guaranteed.
When to use it
- Use
libfyamlwhen you require strict YAML 1.2 semantics. - Use the default
libyamlbackend when throughput and performance are your priority.
Checking the active backend
Use Psych::BACKEND to see which backend is active and Psych.libfyaml_version to check the version.
Psych::BACKEND # => "libfyaml" (or "libyaml")
Psych.libfyaml_version # => "0.9.6"
# Example of YAML 1.2 boolean handling:
Psych.load("country: no") # => {"country" => "no"}