[LLVMdev] Status of YAML IO?

Nick Kledzik kledzik at apple.com
Thu Oct 25 13:05:35 PDT 2012


On Oct 25, 2012, at 9:59 AM, Sean Silva wrote:

>> To better understand how a client would use YAML I/O.  I've completely rewritten the ReaderYAML and WriterYAML in lld to use YAML I/O.  The source code is now about half the size.  But more importantly,  the error checking is much, much better and any time an attribute (e.g. of an Atom) is changed or added, there is just one place to update the yaml code instead of two places (the reader and writer).
> 
> Fantastic!
> 
>> The StringRef ownership works, but is a little clunky.  Because one yaml stream can contain many documents, the ownership of the input file MemoryBuffer cannot be handed off to the newly created lld::File object (which would have allowed any StringRefs provided by the parse to be used as is).  Instead whenever a trait needs to keep a StringRef it must make a copy of the underlying string, and the copies are owned by  the generated lld::File object.
> 
> Copying seems like a performance problem waiting to happen. Maybe this
> could be addressed through reference counting?
There are no separate strings to reference count.  There is just the one big MemoryBuffer which all the parsed StringRefs point into.  

I don't think this is a general issue with YAML I/O.  Most clients will not need to support  multiple documents and will have a natural owner for the MemoryBuffer.   The lld test cases uses multiple yaml documents because lld is a linker and links multiple files.

That said, I think a better implementation for lld's ReaderWriterYAML would be a BumpPtrAllocator per File to hold any strings it needs to copy.

> What are "typical"
> sizes of strings that would be copied?
Most values in key/value pairs are converted to some enum value, so a temporary StringRef into the MemoryBuffer is fine.  The only ones that need to remain as strings are the atoms' names (e.g. "malloc").  

-Nick


> 
> On Wed, Oct 24, 2012 at 9:34 PM, Nick Kledzik <kledzik at apple.com> wrote:
>> 
>> On Oct 22, 2012, at 5:07 PM, Nick Kledzik wrote:
>>> On Oct 22, 2012, at 4:40 PM, Sean Silva wrote:
>>>> Hey Nick, what's the status on YAML IO? The other thread seems to have died.
>>> 
>>> I'm waiting on Michael Spencer's feedback.
>> 
>> To better understand how a client would use YAML I/O.  I've completely rewritten the ReaderYAML and WriterYAML in lld to use YAML I/O.  The source code is now about half the size.  But more importantly,  the error checking is much, much better and any time an attribute (e.g. of an Atom) is changed or added, there is just one place to update the yaml code instead of two places (the reader and writer).
>> 
>> This code requires no changes to the rest of lld.  The traits based approach was thus non-invasive.  It is able to produce yaml from existing data structures and when reading yaml recreate the existing data structures.
>> 
>> The example also shows how context sensitive yaml conversion is done, using io.getContext() to make conversion decisions.
>> 
>> The StringRef ownership works, but is a little clunky.  Because one yaml stream can contain many documents, the ownership of the input file MemoryBuffer cannot be handed off to the newly created lld::File object (which would have allowed any StringRefs provided by the parse to be used as is).  Instead whenever a trait needs to keep a StringRef it must make a copy of the underlying string, and the copies are owned by  the generated lld::File object.
>> 
>> 
>> 
>> 
>> 
>> -Nick
>> 
>> 




More information about the llvm-dev mailing list