diff options
author | Michal Strehovsky <michals@microsoft.com> | 2017-08-14 20:59:13 +0300 |
---|---|---|
committer | Michal Strehovsky <michals@microsoft.com> | 2017-08-14 20:59:13 +0300 |
commit | 1e9054a91177eed92094790ae063a4d741185aa2 (patch) | |
tree | 2b37c7212aed534b66c9843b8cf2b86c0c24925b /src/Native/Runtime/ObjectLayout.h | |
parent | d714e3be0bb99c0f76f3b62ce310878be0b3f66e (diff) |
Speed up string allocations by 35%
`FastAllocateString` (the choke point through which all string allocations go through) wasn't as fast as it could be and we were 30% slower than CLR on allocating strings. We were leaving a lot of perf on the table.
Before this change, string allocation was using the same allocator as arrays. Since there's a subtle difference between the failure modes on overflow (string allocation throws OOM, array allocation throws OverflowException), `FastAllocateString` required a try/catch block to handle the corner case. This was inhibiting codegen optimizations around this code path - to fix that problem, we needed a separate allocator. And since we now had a separate allocator for strings, I also took the liberty of inlining some details around strings (component size and base size) into the helper. It turns out runtime already hardcodes the details around strings (the component size) in a couple places anyway, so this is not that big of a "separation of concerns" violation as it looks like.
[tfs-changeset: 1670224]
Diffstat (limited to 'src/Native/Runtime/ObjectLayout.h')
-rw-r--r-- | src/Native/Runtime/ObjectLayout.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/Native/Runtime/ObjectLayout.h b/src/Native/Runtime/ObjectLayout.h index e088bcccf..8e7e9ba85 100644 --- a/src/Native/Runtime/ObjectLayout.h +++ b/src/Native/Runtime/ObjectLayout.h @@ -100,3 +100,28 @@ public: void* GetArrayData(); }; typedef DPTR(Array) PTR_Array; + +//------------------------------------------------------------------------------------------------- +class String : public Object +{ + friend class AsmOffsets; + friend class StringConstants; + + UInt32 m_Length; + UInt16 m_FirstChar; +}; +typedef DPTR(String) PTR_String; + +//------------------------------------------------------------------------------------------------- +class StringConstants +{ +public: + static UIntNative const ComponentSize = sizeof(((String*)0)->m_FirstChar); + static UIntNative const BaseSize = sizeof(ObjHeader) + offsetof(String, m_FirstChar) + ComponentSize; +}; + +//------------------------------------------------------------------------------------------------- +static UIntNative const STRING_COMPONENT_SIZE = StringConstants::ComponentSize; + +//------------------------------------------------------------------------------------------------- +static UIntNative const STRING_BASE_SIZE = StringConstants::BaseSize; |