Replies: 7 comments 15 replies
-
Does it mean the marshaling won't preserve the order? I know that this was actually one of the argument against using go-toml for mozilla/sops in the first place. On another topic, would you like to add some additional linting (via golangci)? |
Beta Was this translation helpful? Give feedback.
-
I agree with pretty much every word of this. 👍 For the Efficient marshaling goal, I would add that comments would not be preserved. PS - You've probably already seen this, but I'll leave this link here: https://dave.cheney.net/high-performance-json.html. Dave's goals may be different, but it has some interesting ideas to consider. Cc: @bep |
Beta Was this translation helpful? Give feedback.
-
This all looks great to me, and @pelletier -- you doing this upgrade is very much appreciated, and I'm sure I'm not alone thinking that. |
Beta Was this translation helpful? Give feedback.
-
Update on this: I have a branch at https://github.com/pelletier/go-toml/tree/v2-wip that has a brand new scanner/parser and implements More detailed write up to come, and definitely more work to do (especially on performance), but first benchmark looks decent:
(bs = BurntSushi's, v1 is go-toml master, v2 is this branch) This version builds an AST. @renaissanceGeek plan is to build a |
Beta Was this translation helpful? Give feedback.
-
Here is a write up of the unmarshaler implementation: #488 |
Beta Was this translation helpful? Give feedback.
-
@pelletier,
|
Beta Was this translation helpful? Give feedback.
-
Very open to any change! I think those make total sense, will put them in.
|
Beta Was this translation helpful? Give feedback.
-
The goal of this discussion is to gather requirements and feedback on what should go into go-toml v2.
Go-toml has been plagued by several bad design decisions made early on, as this project was just an experiment for me to learn Go and write a parser. As more and more people are migrating from the now unsupported BurntSushi/toml, those issues are becoming bigger blockers for the library adoption.
See also:
Problems
Exposed internals
The
toml.Tree
structure is publicly exposed, but only partially. This creates all sort of confusion and makes fixing the situation impossible without breaking backward compatibility. Just recently we merged a couple changes to expose some functions to unblock some use cases (#466) but that is not a long term solution.Poorly designed API
The
Set*
andGet*
method families are the only official way to get data in/out of a Tree. They are too simplistic in their path access, and they don't account for the fact that data in TOML documents can be heterogeneous. Now that the spec is stable, it seems like a good time to revisit the Tree structure to provide better access patterns.Unmarshaling process is inside-out
This ticket is the main representation of this issue: #252. The process basically creates structs as it parses the file starting at the leaf objects, then assemble them together and eventually set the values on the unamarshal target. This causes overwriting all fields initially set in the target, and cannot be fixed without completely changing the Unmarshal process.
Marshaling speed
Marshal
andUnmarshal
(and there sibling methods onEncoder
andDecoder
) are slow (#167). The main reason for their slowness is that they both require building atoml.Tree
first, then un/marshaling it to the right structure. This creates a considerable amount of overhead, and is not strictly necessary.Decoding information loss
When decoding to a Tree, a lot of information is lost on how the file was composed. This completely prevents a common pattern of loading a file, make some edits, encode the file back. Because information is lost, the encoded modified file may look very different than the loaded file (outside of its purposeful modifications). Issues related to this problem: https://github.com/pelletier/go-toml/milestone/5.
Goals
The first two problems require breaking backward compatibility, so they need to be addressed in part of a "v2" operation. The others can be worked internally, but would require deep changes to the lexer/parser so I feel like they should be considered holistically.
Efficient marshaling
Marshaling is one of the main use-cases of go-toml. Got some TOML doc, map it to a Go struct, do some work, maybe turn it back to bytes. This needs to be an efficient process for projects with large amount of files like Hugo. This process doesn't care much about the final structure of the document once marshaled.
Non-goals
Document editing
The second main use cases for go-toml. This process is about working on a TOML document while respecting its structure. This means preserving comments, key types, table types, ordering, etc.
Non-goals
Beta Was this translation helpful? Give feedback.
All reactions