Skip to content

Commit

Permalink
Byte code size and serialized byte code size optimizations (15-20% se…
Browse files Browse the repository at this point in the history
…rialized byte code size reduction)

Byte code size reductions:
- Variable slot index size in layout

Serialized byte code size reductions:
- Move has loopHeaderArray and has asmJsInfo into the bit field (instead of a byte)
- Don't emit field that has non-zero default value.
- Use the defined fields to indicate existing of more field to reduce serialized byte code size
- Use constant type to indicate whether it is property string or not instead of an extra boolean
- Add int8 and int16 constant type for small int encoding in the constant table
- Separate out the byte offset from the character offset in the LineOffsetCache so that we can omit them if the source is purely ASCII-7
    -Reduce by half the memory used by the LineOffsetCache for ASCII-7 sources, and it reduces the serialized byte code size as well.
- Remove unused sourceSpans from byte code serialization.
- Serialize the bit flag with constant encoding (since the bit flag always as a large value)

Also:
- Clean up unused Reg2WithICIndex and REg1Int2 layout
- Move LineOffsetCache to Runtime/Base instead of Common/DataStructures, and de-templatize it as we only use Recycler as the allocator anyway.
  • Loading branch information
curtisman committed Aug 28, 2017
1 parent 88a2c3a commit c45931a
Show file tree
Hide file tree
Showing 32 changed files with 13,333 additions and 16,804 deletions.
57 changes: 1 addition & 56 deletions lib/Backend/IRBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1988,36 +1988,6 @@ IRBuilder::BuildReg2(Js::OpCode newOpcode, uint32 offset, Js::RegSlot R0, Js::Re
this->AddInstr(instr, offset);
}

template <typename SizePolicy>
void
IRBuilder::BuildReg2WithICIndex(Js::OpCode newOpcode, uint32 offset)
{
AssertMsg(false, "NYI");
}

template <typename SizePolicy>
void
IRBuilder::BuildProfiledReg2WithICIndex(Js::OpCode newOpcode, uint32 offset)
{
Assert(OpCodeAttr::IsProfiledOpWithICIndex(newOpcode));
Assert(OpCodeAttr::HasMultiSizeLayout(newOpcode));
auto layout = m_jnReader.GetLayout<Js::OpLayoutDynamicProfile<Js::OpLayoutT_Reg2WithICIndex<SizePolicy>>>();

if (!PHASE_OFF(Js::ClosureRegCheckPhase, m_func))
{
this->DoClosureRegCheck(layout->R0);
this->DoClosureRegCheck(layout->R1);
}

BuildProfiledReg2WithICIndex(newOpcode, offset, layout->R0, layout->R1, layout->profileId, layout->inlineCacheIndex);
}

void
IRBuilder::BuildProfiledReg2WithICIndex(Js::OpCode newOpcode, uint32 offset, Js::RegSlot dstRegSlot, Js::RegSlot srcRegSlot, Js::ProfileId profileId, Js::InlineCacheIndex inlineCacheIndex)
{
BuildProfiledReg2(newOpcode, offset, dstRegSlot, srcRegSlot, profileId, inlineCacheIndex);
}

///----------------------------------------------------------------------------
///
/// IRBuilder::BuildProfiledReg2
Expand All @@ -2043,7 +2013,7 @@ IRBuilder::BuildProfiledReg2(Js::OpCode newOpcode, uint32 offset)
}

void
IRBuilder::BuildProfiledReg2(Js::OpCode newOpcode, uint32 offset, Js::RegSlot dstRegSlot, Js::RegSlot srcRegSlot, Js::ProfileId profileId, Js::InlineCacheIndex inlineCacheIndex)
IRBuilder::BuildProfiledReg2(Js::OpCode newOpcode, uint32 offset, Js::RegSlot dstRegSlot, Js::RegSlot srcRegSlot, Js::ProfileId profileId)
{
bool switchFound = false;

Expand Down Expand Up @@ -2112,7 +2082,6 @@ IRBuilder::BuildProfiledReg2(Js::OpCode newOpcode, uint32 offset, Js::RegSlot ds
IR::JitProfilingInstr *profiledInstr = IR::JitProfilingInstr::New(newOpcode, dstOpnd, src1Opnd, m_func);
profiledInstr->profileId = profileId;
profiledInstr->isBeginSwitch = newOpcode == Js::OpCode::Ld_A;
profiledInstr->inlineCacheIndex = inlineCacheIndex;
instr = profiledInstr;
}
else if(isProfiled)
Expand Down Expand Up @@ -2834,30 +2803,6 @@ IRBuilder::BuildUnsigned1(Js::OpCode newOpcode, uint32 offset, uint32 num)
}
}

void
IRBuilder::BuildReg1Int2(Js::OpCode newOpcode, uint32 offset)
{
Assert(!OpCodeAttr::HasMultiSizeLayout(newOpcode));

const unaligned Js::OpLayoutReg1Int2 *regLayout = m_jnReader.Reg1Int2();
Js::RegSlot R0 = regLayout->R0;
int32 C1 = regLayout->C1;
int32 C2 = regLayout->C2;

if (!PHASE_OFF(Js::ClosureRegCheckPhase, m_func))
{
this->DoClosureRegCheck(R0);
}

IR::RegOpnd* dstOpnd = this->BuildDstOpnd(R0);

IR::IntConstOpnd * srcOpnd = IR::IntConstOpnd::New(C1, TyInt32, m_func);
IR::IntConstOpnd * src2Opnd = IR::IntConstOpnd::New(C2, TyInt32, m_func);
IR::Instr* instr = IR::Instr::New(newOpcode, dstOpnd, srcOpnd, src2Opnd, m_func);

this->AddInstr(instr, offset);
}

template <typename SizePolicy>
void
IRBuilder::BuildProfiledReg1Unsigned1(Js::OpCode newOpcode, uint32 offset)
Expand Down
3 changes: 1 addition & 2 deletions lib/Backend/IRBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ class IRBuilder

void BuildReg1(Js::OpCode newOpcode, uint32 offset, Js::RegSlot R0);
void BuildReg2(Js::OpCode newOpcode, uint32 offset, Js::RegSlot R0, Js::RegSlot R1, uint32 nextOffset);
void BuildProfiledReg2(Js::OpCode newOpcode, uint32 offset, Js::RegSlot dstRegSlot, Js::RegSlot srcRegSlot, Js::ProfileId profileId, Js::InlineCacheIndex inlineCacheIndex = Js::Constants::NoInlineCacheIndex);
void BuildProfiledReg2WithICIndex(Js::OpCode newOpcode, uint32 offset, Js::RegSlot dstRegSlot, Js::RegSlot srcRegSlot, Js::ProfileId profileId, Js::InlineCacheIndex inlineCacheIndex);
void BuildProfiledReg2(Js::OpCode newOpcode, uint32 offset, Js::RegSlot dstRegSlot, Js::RegSlot srcRegSlot, Js::ProfileId profileId);
void BuildReg3(Js::OpCode newOpcode, uint32 offset, Js::RegSlot dstRegSlot, Js::RegSlot src1RegSlot,
Js::RegSlot src2RegSlot, Js::ProfileId profileId);
void BuildReg3C(Js::OpCode newOpCode, uint32 offset, Js::RegSlot dstRegSlot, Js::RegSlot src1RegSlot,
Expand Down
4 changes: 1 addition & 3 deletions lib/Backend/Lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8130,7 +8130,7 @@ Lowerer::LowerUnaryHelperMemWithFuncBody(IR::Instr *instr, IR::JnHelperMethod he
IR::Instr *
Lowerer::LowerBinaryHelperMemWithFuncBody(IR::Instr *instr, IR::JnHelperMethod helperMethod)
{
AssertMsg(Js::OpCodeUtil::GetOpCodeLayout(instr->m_opcode) == Js::OpLayoutType::Reg1Int2, "Expected a binary instruction...");
AssertMsg(Js::OpCodeUtil::GetOpCodeLayout(instr->m_opcode) == Js::OpLayoutType::Reg3, "Expected a binary instruction...");

m_lowererMD.LoadHelperArgument(instr, this->LoadFunctionBodyOpnd(instr));
return this->LowerBinaryHelperMem(instr, helperMethod);
Expand Down Expand Up @@ -8217,7 +8217,6 @@ Lowerer::LowerBinaryHelper(IR::Instr *instr, IR::JnHelperMethod helperMethod)
AssertMsg((Js::OpCodeUtil::GetOpCodeLayout(instr->m_opcode) == Js::OpLayoutType::Reg1Unsigned1 && !instr->GetDst()) ||
Js::OpCodeUtil::GetOpCodeLayout(instr->m_opcode) == Js::OpLayoutType::Reg3 ||
Js::OpCodeUtil::GetOpCodeLayout(instr->m_opcode) == Js::OpLayoutType::Reg2Int1 ||
Js::OpCodeUtil::GetOpCodeLayout(instr->m_opcode) == Js::OpLayoutType::Reg1Int2 ||
Js::OpCodeUtil::GetOpCodeLayout(instr->m_opcode) == Js::OpLayoutType::ElementU ||
instr->m_opcode == Js::OpCode::InvalCachedScope, "Expected a binary instruction...");

Expand All @@ -8241,7 +8240,6 @@ Lowerer::LowerBinaryHelperMem(IR::Instr *instr, IR::JnHelperMethod helperMethod)

AssertMsg(Js::OpCodeUtil::GetOpCodeLayout(instr->m_opcode) == Js::OpLayoutType::Reg3 ||
Js::OpCodeUtil::GetOpCodeLayout(instr->m_opcode) == Js::OpLayoutType::Reg2Int1 ||
Js::OpCodeUtil::GetOpCodeLayout(instr->m_opcode) == Js::OpLayoutType::Reg1Int2 ||
Js::OpCodeUtil::GetOpCodeLayout(instr->m_opcode) == Js::OpLayoutType::Reg1Unsigned1, "Expected a binary instruction...");

instrPrev = LoadScriptContext(instr);
Expand Down
1 change: 0 additions & 1 deletion lib/Common/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ template<> struct IntMath<int64> { using Type = Int64Math; };
#include "DataStructures/GrowingArray.h"
#include "DataStructures/EvalMapString.h"
#include "DataStructures/RegexKey.h"
#include "DataStructures/LineOffsetCache.h"

#include "Core/ICustomConfigFlags.h"
#include "Core/CmdParser.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
<ClInclude Include="GrowingArray.h" />
<ClInclude Include="ImmutableList.h" />
<ClInclude Include="Interval.h" />
<ClInclude Include="LineOffsetCache.h" />
<ClInclude Include="LeafValueDictionary.h" />
<ClInclude Include="MruDictionary.h" />
<ClInclude Include="PageStack.h" />
Expand Down
Loading

0 comments on commit c45931a

Please sign in to comment.