-
Notifications
You must be signed in to change notification settings - Fork 344
[lldb] Implement cache for swift typeref metadata #5100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[lldb] Implement cache for swift typeref metadata #5100
Conversation
Leaving this as a draft for now as it depends on some upstream changes. |
Accompanying swift patch: swiftlang/swift#60497 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow that's quite a patch :-)
Some first thoughts inline!
lldb/source/Core/CoreProperties.td
Outdated
def EnableSwiftMetadataCache: Property<"enable-swift-metadata-cache", "Boolean">, | ||
Global, | ||
DefaultFalse, | ||
Desc<"Enable caching for swift reflection metadata in LLDB.">; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
above swift
is spelled Swift
nullptr, idx, g_modulelist_properties[idx].default_uint_value != 0); | ||
} | ||
|
||
uint64_t ModuleListProperties::GetSwiftMetadataCacheMaxByteSize() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should write macros for these functions :-)
lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntimeDynamicTypeResolution.cpp
Outdated
Show resolved
Hide resolved
lldb/source/Plugins/LanguageRuntime/Swift/SwiftMetadataCache.cpp
Outdated
Show resolved
Hide resolved
lldb/source/Plugins/LanguageRuntime/Swift/SwiftMetadataCache.cpp
Outdated
Show resolved
Hide resolved
lldb/source/Plugins/LanguageRuntime/Swift/SwiftMetadataCache.cpp
Outdated
Show resolved
Hide resolved
Similarly to the clang module cache, we need to localize this cache to the test dir when running the LLDB test suite. |
8d4b8fb
to
aa092d6
Compare
aa092d6
to
30d4de6
Compare
lldb/source/Plugins/LanguageRuntime/Swift/SwiftMetadataCache.cpp
Outdated
Show resolved
Hide resolved
LLDB_LOG(log, | ||
"[SwiftMetadataCache] Failed to read cached UUID for module {0}.", | ||
module->GetFileSpec().GetFilename()); | ||
m_data_file_cache->RemoveCacheFile(module_name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have expected RemoveCacheFile() to be called immediately before a new file is written. What's the flow if the cache is stale?
loadCacheForModule() deletes the cache, but where is a new one written?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new one is written in registerFieldDescriptors
, which is when we have new data to cache. I think it makes sense to delete the cache immediately if it's stale/corrupted. Since we're including the lldb version as part of the hash now I don't think there would be any advantages in doing that later. Doing it earlier is also nice because we clear up disk space.
const auto *start = (const char *)header_extractor.GetData(&read_offset, 0); | ||
// Create a reference to the compressed data. | ||
llvm::StringRef string_buffer(start, (uint64_t)mem_buffer_up->getBufferEnd() - | ||
(uint64_t)start); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
membuffer_up->getBuffer() ?
https://llvm.org/doxygen/classllvm_1_1MemoryBuffer.html#a2ea075bd68f15b57e95f0771b8ba0bca
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean getBufferSize
? If so, we can't do that because we have to subtract the header we just read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, I didn't realize that start is not the start of the buffer,
To make sure this didn't get lost:
|
I don't understand what you mean by this. Do you mean when running tests in general? We can probably leave it off in general, and turn it on only when testing this feature. |
e94cc80
to
c3a8235
Compare
c3a8235
to
b65c0e3
Compare
Yes, something like this: https://github.com/llvm/llvm-project/blob/cd3a234fa9272f90dcfad3158cd9b51a0e643d1b/lldb/packages/Python/lldbsuite/test/lldbtest.py#L729 Turning it off and on only for the test is fine, if we can make the testsuite faster by sharing a cache for an entire test suite run, then that's great, too. |
lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.cpp
Outdated
Show resolved
Hide resolved
b65c0e3
to
a236ada
Compare
if (llvm::sys::path::cache_directory(path)) { | ||
llvm::sys::path::append(path, "lldb"); | ||
llvm::sys::path::append(path, "SwiftMetadataCache"); | ||
lldbassert(SetLLDBIndexCachePath(FileSpec(path))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
/// A map from reflection infos ids to a pair constituting of its | ||
/// corresponding module and whether or not we've inserted the cached metadata | ||
/// for that reflection info already. | ||
std::unordered_map<uint64_t, std::pair<lldb::ModuleSP, bool>> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this an unordered_map and not a std::vector<>? I would have expected the ids to be in a contiguous range?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There could be holes since we don't register JITed modules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, so the uint64_t is not the index that shows up in image list
but the index of refkection sections we register with the runtime. The first 100 or so elements are identical, but that's it. And during a session the list grows steadily, and there could by dylibs loaded after a JIT session.
Last question: would a uint32_t suffice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think so, I doubt we'd ever have more than 4294967295 reflection infos :)
lldb/test/API/lang/swift/metadata_cache/TestSwiftMetadataCache.py
Outdated
Show resolved
Hide resolved
lldb/test/API/lang/swift/metadata_cache/TestSwiftMetadataCache.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with a few minor nits inline
a236ada
to
e5699c7
Compare
1 similar comment
e5699c7
to
02806bc
Compare
61f06a3
to
cdcb91a
Compare
Implement a mechanism to cache field descriptor location information. One of the main problems of using type metadata as debug info, when in comes to field descriptors in particular, is that there's no easy way to find the correct type given a (string key), so a linear search over every source of reflection information must be done. This patch implements a cache which allows for field descriptors to be found in a more efficient manner.
cdcb91a
to
80e10a6
Compare
The new test is failing on linux because the bot doesn't have zlib installed, so the cache is disabled as well. Since I have a new patch, which doesn't require zlib, ready to be put up for review after this one is merged, I'm temporarily skipping linux, and will re-enable it on the next patch. |
No description provided.