Reviewers: danno,
Message:
Hi Danno,
We can reduce transitions with information at parse time. It's an old CL,
found
in the closet :p.
Thx,
--Michael
Description:
Reduce elements transitions when compiling boilerplates.
The idea is to recognize if an array literal contains doubles, and allocate
a
double array upfront.
It reduces the # of transitions in the Kraken benchmark to ~2300 from ~6400.
BUG=
Please review this at https://codereview.chromium.org/12970007/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+15, -3 lines):
M src/parser.cc
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index
a17883fd456182865a90a1b76225ff02ae826ddb..7667995096138d9a15cafc633da405b13264caa6
100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -3640,6 +3640,8 @@ Expression* Parser::ParsePrimaryExpression(bool* ok) {
Expression* Parser::ParseArrayLiteral(bool* ok) {
// ArrayLiteral ::
// '[' Expression? (',' Expression?)* ']'
+ bool seen_doubles = false;
+ bool is_holey = false;
int pos = peek_position();
ZoneList<Expression*>* values = new(zone()) ZoneList<Expression*>(4,
zone());
@@ -3648,8 +3650,14 @@ Expression* Parser::ParseArrayLiteral(bool* ok) {
Expression* elem;
if (peek() == Token::COMMA) {
elem = GetLiteralTheHole(peek_position());
+ is_holey = true;
} else {
elem = ParseAssignmentExpression(true, CHECK_OK);
+ if (elem->AsLiteral() != NULL) {
+ if (elem->AsLiteral()->value()->IsHeapNumber()) {
+ seen_doubles = true;
+ }
+ }
}
values->Add(elem, zone());
if (peek() != Token::RBRACK) {
@@ -3662,8 +3670,13 @@ Expression* Parser::ParseArrayLiteral(bool* ok) {
int literal_index =
current_function_state_->NextMaterializedLiteralIndex();
// Allocate a fixed array to hold all the object literals.
+ ElementsKind kind = FAST_HOLEY_SMI_ELEMENTS;
+ if (seen_doubles) {
+ kind = FAST_HOLEY_DOUBLE_ELEMENTS;
+ }
+
Handle<JSArray> array =
- isolate()->factory()->NewJSArray(0, FAST_HOLEY_SMI_ELEMENTS);
+ isolate()->factory()->NewJSArray(0, kind);
isolate()->factory()->SetElementsCapacityAndLength(
array, values->length(), values->length());
@@ -3671,7 +3684,6 @@ Expression* Parser::ParseArrayLiteral(bool* ok) {
Heap* heap = isolate()->heap();
bool is_simple = true;
int depth = 1;
- bool is_holey = false;
for (int i = 0, n = values->length(); i < n; i++) {
MaterializedLiteral* m_literal =
values->at(i)->AsMaterializedLiteral();
if (m_literal != NULL && m_literal->depth() + 1 > depth) {
@@ -3702,7 +3714,7 @@ Expression* Parser::ParseArrayLiteral(bool* ok) {
// in a 2-element FixedArray.
Handle<FixedArray> literals = isolate()->factory()->NewFixedArray(2,
TENURED);
- ElementsKind kind = array->GetElementsKind();
+ kind = array->GetElementsKind();
kind = is_holey ? GetHoleyElementsKind(kind) :
GetPackedElementsKind(kind);
literals->set(0, Smi::FromInt(kind));
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.