-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Avoid malloc allocations in the runtime #23131
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
Conversation
@swift-ci test |
@compnerd Can you please review my changes in LLVMSupport.cpp? I'm not sure what's the purpose of swiftCore_EXPORTS there. I had to remove it to be able to compiler the reflection library. |
Build failed |
@swift-ci test linux |
This is a nice performance boost, but do we know why the cast is exercising the remangler so heavily to begin with? |
@eeckstein can we add a benchmark or an interpreter test that measures the malloc traffic to make sure we don't regress? |
@jckarter No. That's definitely also worth investigating. |
@gottesmm That's a good point. I'll try to add a benchmark |
@swift-ci benchmark |
Build failed |
Build failed |
@eeckstein - the reason for the LLVMSupport doing the evil things with |
/// on POD-like datatypes and is out of line to reduce code duplication. | ||
void | ||
#if !defined(_WIN32) | ||
__attribute__((__weak__, __visibility__("hidden"))) |
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 need to use the alternatename for providing the default implementation on Windows.
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.
Can you give me a patch for that? Or change it after this PR is merged?
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.
Sure, I'll get you a patch (need to wait for my current build to finish first). I'd rather not break the Windows build in the meantime, because the other breakages then pile up.
OK, but LLVMSupport.cpp is only linked when building swiftCore, but not when building the host tools. So why would we need a #ifdef swiftCore_EXPORTS over the whole file? |
Performance: -O
Performance: -Osize
Performance: -Onone
Code size: -swiftlibs
How to read the dataThe tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.If you see any unexpected regressions, you should consider fixing the Noise: Sometimes the performance results (not code size!) contain false Hardware Overview
|
The problem is that the dependency percolates through, particularly for the tests IIRC. |
There are also people who want to link Swift into binaries that also include their own copy of LLVM, and not have Swift's use of some bits of LLVMSupport for its own purpose to leak through. |
34d373e
to
5666bf2
Compare
std::vector<BuiltType> paramTypes; | ||
std::vector<uint32_t> paramFlags; | ||
SmallVector<BuiltType, 8> paramTypes; | ||
SmallVector<uint32_t, 8> paramFlags; | ||
|
||
// Fill in the parameters. | ||
paramTypes.reserve(params.size()); |
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.
Just checking, the reserve is still fine after?
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, should be fine
…internal substitution data structures This avoids mallocs in the runtime. SR-10028 rdar://problem/48575729
…llvm's SmallPtrSet. This avoids malloc calls in the common case. Only if there are more than 16 substitutions in the fixed-sized array, the overflow goes into a std::unordered_map. SR-10028 rdar://problem/48575729
…ations in most cases. This dramatically reduces the number of needed malloc calls. Unfortunately I had to add the implementation of SmallVectorBase::grow_pod to the runtime, as we don't link LLVM. This is a bad hack, but better than re-inventing a new SmallVector implementation. SR-10028 rdar://problem/48575729
Instead of capturing SubstGenericParametersFromMetadata and SubstGenericParametersFromWrittenArgs by value, capture by reference. This avoids those instances to be copied and thus avoids a lot of mallocs. SR-10028 rdar://problem/48575729
Done by replacing DemanglerPrinter with a bump-pointer allocated CharVector buffer. This avoids malloc calls. SR-10028 rdar://problem/48575729
…meters and arguments don't match. This can happen if _typeByName() is called with an invalid mangled type name.
5666bf2
to
0dd2495
Compare
@compnerd I re-added #if defined(swiftCore_EXPORTS) in LLVMSupport.cpp. |
@swift-ci test |
@swift-ci test |
Yeap, I'll create a modification of this patch for that. |
Build failed |
@swift-ci test macOS |
1 similar comment
@swift-ci test macOS |
@eeckstein - btw, for future reference (and mostly myself) - the other use of |
@eeckstein - seems that without the aliasing it also works. I imagine that the definition here is just being given precedence to the one in LLVMSupport. Seems to be working in my local test. |
@compnerd Great, thanks for testing it! |
Reintroduce some changes done in swiftlang#23131 to hide some weak symbols generated when compiling as part of libswiftDemangle.dylib, which may introduce a performance regression. Addresses rdar://63454568
This PR consists of multiple commits:
See the commit messages for details.
Fixes https://bugs.swift.org/browse/SR-10028, rdar://problem/48575729
It eliminates all allocations in the cast operation.
to-do: make the old remangler allocation free.