[LLVMdev] RFC: Binary format for instrumentation based profiling data
Justin Bogner
mail at justinbogner.com
Wed Apr 16 12:48:03 PDT 2014
Bob Wilson <bob.wilson at apple.com> writes:
> On Apr 16, 2014, at 12:21 AM, Chandler Carruth <chandlerc at google.com> wrote:
> The OnDiskHashTable stuff seems perfectly fine for emitting just that - an
> on-disk-hash-table. However, it was never designed to support long-lived
> file formats in that form. The use in serialized ASTs is specifically not
> supporting a long-term file format. The biggest issue there is endianness,
> and I see you've already very nicely added good support for that. The only
> remaining concern I might have are the 32-bit offset limitations. While >
> 2gb of counter data may seem unlikely, I don't think it is inconceivable,
> and even >4gb of counter data might happen. Using 64-bit offsets seems an
> easy fix though. Essentially, I think this part of the code could quickly
> and easily be made viable for this purpose, although it would require a
> bit more cleanup and documenting the intended stability.
>
> It wouldn’t surprise me at all if we eventually need larger than 32-bit
> offsets, but I don’t think that’s a priority right now. We have almost no
> knowledge of the typical size of these PGO profiles, and no one is even using
> this new feature yet. More importantly, it would be good to share the basic
> OnDiskHash table implementation for clang’s serialized ASTs and modules and
> I’m concerned that it might be disruptive to change that right now. We’re
> almost certainly going to be changing the file format over time and we can
> coordinate a change to 64-bit offsets later if that turns out to be important.
Adding an extra template parameter (offset_type?) to the OnDiskHashTable
classes would be pretty trivial, we can even default it to uint32_t for
the pre-existing clang usages to minimize churn. Given how easy this is
to do, it's probably worth doing now.
> Anyways, the part I was truly concerned about is actually nicely factored
> out -- the hashing bit. The AST's hashing is *completely* unsuitable for a
> long-term file format, but my assumption is that you'd just use the
> existing stable PGO hashing stuff for this table? If so, it should work
> fine. If you want to hash other things (function names?), I would just
> urge using something like their MD5 or some other fixed, and
> uncontroversial algorithm so we don't end up wondering how a bug snuck in
> there N years later. So this seems workable too.
>
> The PGO hashing is completely unrelated. The hash here is just of the function
> name (or more specifically, the name that we used in the PGO data, e.g.,
> possibly mangled). We’re currently using Bernstein’s hash function, which is
> so simple that I’m not worried about bugs, but it isn’t a great hash function.
> MD5 would make sense to me.
Yes, these are hashes of the function names. The OnDiskHashTable
currently expects a 32 bit hash, so I think we should add a
hash_value_type template parameter as well, then use 64 bits of an MD5
here. Agreed?
Chandler Carruth <chandlerc at google.com> writes:
> Essentially, to answer a later question:
>
> If you're opposed to moving the existing OnDiskHashTable into Support,
> perhaps because you don't think it should proliferate to other uses,
> the obvious alternative is to include a private copy of a stripped down
> version of it for the profile reader and writer to use themselves. I'm
> not sure if this is worth the copy pasted code, but it is an
> option. What do you think?
>
> I think with the cleanups you've started plus a bit more documentation, this
> could be a fine candidate for a generic on-disk (or, raw memory buffer) hash
> table writer and reader.
Great. I'll go ahead and move the hash table now, and I'll add some
documentation while I'm at it. I'm going to put it in llvm/Support/,
and keep the OnDiskHashTable.h name.
Then I'll go ahead and write up the patches for choosing the offset and
hash value types, and then move on to using this in InstrProf and
updating the clang clients.
> OK, on to the general questions rather than ones concerning specific code...
>
> > I have a general preference for from-disk lookups to use tries (for
> strings,
> > prefix tries) or other fast, sorted lookup structures. They have the
> nice
> > property of being inherently stable and unambiguous, and not baking any
> > hashing algorithm into it.
>
> I would like to experiment with a few trie-based approaches for this as
> we try to optimize the PGO process further (both for space and for
> lookup time). Even so, it's not a sure thing that this will work better,
>
> So the first question is whether it is really worth looking into other
> solutions. I have a suspicion that there are better formats for this because
> of one key idea: while the important operation is lookup, I don't think it is
> truly *random* lookup. In fact, I suspect it will be extremely structured
> lookup, with a few hot clusters of data due to similar function "names" (where
> the names of things like file-local static functions get file name prefixes
> and such to disambiguate them). So I think that there is a real locality win
> possible in this space. Maybe not all the time, and most of the time it may be
> below the noise floor, but I think it will still be there.
Right, data locality and an abundance of shared prefixes make this data
set kind of interesting. I agree it's worth experimenting, but I do
think we need this in as a baseline first.
> and I don't think it's worth delaying getting something that people can
> use out the door.
>
> If the file format is wide open to change over the coming months, then I'm
> totally down with this. Makes perfect sense. However, I get the feeling that
> it isn't wide open to change, and we're going to quickly end up locked into a
> particular format here to support the backwards compatibility concerns.
> Personally, I'm happy to change the format *very* fluidly, at least until
> there is an LLVM release, and potentially even after that, but it would be
> good to hear from others that want to consume this data.
I'm happy with making changes here too. Once we have an LLVM release
with this in it, then changes will need to come with a story on how
users upgrade their old data to the changed format, but we shouldn't let
that stop us from improving things.
More information about the llvm-dev
mailing list