-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Make the demangler in the runtime use stack allocated memory. #22655
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
Make the demangler in the runtime use stack allocated memory. #22655
Conversation
This is done by disallowing nodes with children to also have index or text payloads. In some cases those payloads were not needed anyway, because the information can be derived later. In other cases the fix was to insert an additional child node with the index/text payload. Also, implement single or double children as "inline" children, which avoids needing a separate node vector for children. All this reduces the needed size for node trees by over 2x.
Log allocated memory and indent according to the nesting level
The demangler can be initialized with a preallocated memory on the stack. Only in case of an overflow, the bump pointer allocator mallocs new memory. Also, support that a new instance of a demangler can "borrow" the free memory from an existing demangler. This is useful because in the runtime the demangler is invoked recursively. With this feature, all the nested demanglers can share a single stack allocated space.
This reduces the amount of mallocs significantly.
@swift-ci test |
@swift-ci benchmark |
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
|
if (CurrentSlab) { | ||
#ifdef NODE_FACTORY_DEBUGGING | ||
std::cerr << indent() << "## clear: allocated memory = " << allocatedMemory << "\n"; | ||
#endif |
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.
Would LLVM's DEBUG(...) macros work from the runtime?
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 didn't try, but we are not linking llvm to the runtime
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, thanks for doing this Erik!
A big part of the change is to reduce the size of demangler Node: This is done by disallowing nodes with children to also have index or text payloads.
In some cases those payloads were not needed anyway, because the information can be derived later.
In other cases the fix was to insert an additional child node with the index/text payload.
The demangler now supports stack allocated memory for its allocator.
The demangler can be initialized with a preallocated memory on the stack. Only in case of an overflow, the bump pointer allocator mallocs new memory.
Also, support that a new instance of a demangler can "borrow" the free memory from an existing demangler. This is useful because in the runtime the demangler is invoked recursively. With this feature, all the nested demanglers can share a single stack allocated space.
rdar://problem/47357709