From 37e643696f860094ca3182c87f1375540b9d704e Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Fri, 4 May 2018 10:40:28 -0700 Subject: Fix System.String over-allocation (#17876) BaseSize for System.String was not set correctly. It caused unnecessary extra 8 bytes to be allocated at the end of strings that had `Length % 4 < 2` on 64-bit platforms. This change makes affected strings proportionally cheaper. For example, `new string('a', 1)` in a long-running loop is 7% faster. --- src/vm/i386/jitinterfacex86.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/vm/i386') diff --git a/src/vm/i386/jitinterfacex86.cpp b/src/vm/i386/jitinterfacex86.cpp index 642c417598..4eccd35a76 100644 --- a/src/vm/i386/jitinterfacex86.cpp +++ b/src/vm/i386/jitinterfacex86.cpp @@ -1063,14 +1063,13 @@ void *JIT_TrialAlloc::GenAllocString(Flags flags) // jae noLock - seems tempting to jump to noAlloc, but we haven't taken the lock yet sl.X86EmitCondJump(noLock, X86CondCode::kJAE); - // mov edx, [ecx]MethodTable.m_BaseSize - sl.X86EmitIndexRegLoad(kEDX, kECX, offsetof(MethodTable,m_BaseSize)); - // Calculate the final size to allocate. // We need to calculate baseSize + cnt*2, then round that up by adding 3 and anding ~3. - // lea eax, [edx+eax*2+5] - sl.X86EmitOp(0x8d, kEAX, kEDX, (DATA_ALIGNMENT-1), kEAX, 2); + // lea eax, [basesize+(alignment-1)+eax*2] + sl.Emit16(0x048d); + sl.Emit8(0x45); + sl.Emit32(StringObject::GetBaseSize() + (DATA_ALIGNMENT-1)); // and eax, ~3 sl.Emit16(0xe083); -- cgit v1.2.3