Open asl opened 4 months ago
Is the invocation of these functions somewhere on the critical path for the compiler?
Is the invocation of these functions somewhere on the critical path for the compiler?
Depends. But some backends essentially produce jsons only. I know also downstream cases where lots of jsons are emitted for control plane, etc.
json library is a heavy cstring user for no particular reason. Essentially, jsons are huge string-keyed dictionaries. Let's see the common example of usage (this is from
bfruntime.cpp
):emplace
itself is essentially:Lots of bad things here:
cstring
. We have string cache lookup (or two if the value should be inserted) here. Plus, if the label is new, then it is copied and remembered foreverordered_map::emplace
. Now usingcstring
's data pointer. Given thatordered_map
is just plain slowstd::map
this is not so good. Actually, there are two map lookups here due to presence of value check, but this could be optimized with better iterator usage.As a results, jsons are quite expensive both memory- and performance- wise. Also, they pollute string cache for no particular reason. These strings are never released.
I think the proper solution would be to have a specialized StringMap container. Specialized towards string keys. Given that we'd always need to have string cache lookup currently, it will be uniformly better :)