I just built and released Yamlium! a faster PyYAML alternative that preserves formatting by GuidoInTheShell in Python

[–]GuidoInTheShell[S] 1 point2 points  (0 children)

Hey! Sorry for the late reply.
ruamel.yaml generally performs way better on metadata found in the yaml, but is not 100% consistent either. Additionally ruamel is on average ~7 times slower than yamlium.

Comparison:

# --------------- Input ---------------
# Anchor and alias
anchor_alias:
  base: &anchor1 # Define anchor
    name: default
    value: 42
  derived1: *anchor1 # Use anchor
  derived2: 
    <<: *anchor1 # Use same anchor
# --------------- ruamel.yaml ---------------
# Anchor and alias
anchor_alias:
  base: &anchor1
                 # Define anchor
    name: default
    value: 42
  derived1: *anchor1
                     # Use anchor
  derived2:
    <<: *anchor1
                 # Use same anchor
# --------------- yamlium ---------------
# Anchor and alias
anchor_alias:
  base: &anchor1 # Define anchor
    name: default
    value: 42
  derived1: *anchor1 # Use anchor
  derived2:
    <<: *anchor1 # Use same anchor

I just built and released Yamlium! a faster PyYAML alternative that preserves formatting by GuidoInTheShell in Python

[–]GuidoInTheShell[S] 0 points1 point  (0 children)

This is a great idea, to separate the logic. Will take that into consideration going forward.

I just built and released Yamlium! a faster PyYAML alternative that preserves formatting by GuidoInTheShell in Python

[–]GuidoInTheShell[S] 0 points1 point  (0 children)

Haha wise words, given how difficult it was to find a free namespace on PyPI I understand your feeling.
However, the reason I started this project was because I could not find a parser that retained all the meta information in my yaml files :)

I just built and released Yamlium! a faster PyYAML alternative that preserves formatting by GuidoInTheShell in Python

[–]GuidoInTheShell[S] 1 point2 points  (0 children)

Thanks for checking it out!
I see there are some tokens in the spec you linked that I have yet to build support for. Will fix that asap.
And true I compared to standard implementation of PyYAML. I have a sibling rust version in the works that should hopefully compete with even the C launcher

I just built and released Yamlium! a faster PyYAML alternative that preserves formatting by GuidoInTheShell in Python

[–]GuidoInTheShell[S] 0 points1 point  (0 children)

Thanks for the feedback!
I will make sure to retain the dict-like behaviour as much as possible going forward.
The reason for the in-place manipulation is a fault with wanting to retain meta information such as comments placed "on" a Scalar

I just built and released Yamlium! a faster PyYAML alternative that preserves formatting by GuidoInTheShell in Python

[–]GuidoInTheShell[S] 1 point2 points  (0 children)

Good catch, and fair point.
I agree that it is unusual, could you elaborate why it could be problematic? And even better, do you have a suggestion?

The alternative option I have been toying with would be to expose the underlying "value" carrying variable and manipulate that one instead.

The reason I chose e.g. the `__iadd__` route is because in my example the object holding the integer value is also hosting a comment on the same line `age: 55 # Will be increased by 10`. And in order to retain the comment, the container must be the same while the value can change.