Revision: 9928
Author: [email protected]
Date: Wed Nov 9 04:15:35 2011
Log: A page created a number of ConsStrings that refer to one big
string.
Each such string requires small amount of heap memory.
Heap snapshot generator copies all the strings into internal hash map for
future use.
The each copy requires much more memory than original v8 string.
I made a workaround for this. The snapshot will copy only first 1024
symbols.
A simple drive-by fix was made for a performance problem in ToCString
implementation.
BUG=v8:1816
TEST=none
Review URL: http://codereview.chromium.org/8509003
Patch from Ilya Tikhonovsky <[email protected]>.
http://code.google.com/p/v8/source/detail?r=9928
Modified:
/branches/bleeding_edge/src/objects.cc
/branches/bleeding_edge/src/profile-generator.cc
/branches/bleeding_edge/src/profile-generator.h
=======================================
--- /branches/bleeding_edge/src/objects.cc Tue Nov 8 03:59:56 2011
+++ /branches/bleeding_edge/src/objects.cc Wed Nov 9 04:15:35 2011
@@ -5826,12 +5826,9 @@
buffer->Reset(offset, this);
int character_position = offset;
int utf8_bytes = 0;
- while (buffer->has_more()) {
+ while (buffer->has_more() && character_position++ < offset + length) {
uint16_t character = buffer->GetNext();
- if (character_position < offset + length) {
- utf8_bytes += unibrow::Utf8::Length(character);
- }
- character_position++;
+ utf8_bytes += unibrow::Utf8::Length(character);
}
if (length_return) {
@@ -5845,16 +5842,13 @@
buffer->Seek(offset);
character_position = offset;
int utf8_byte_position = 0;
- while (buffer->has_more()) {
+ while (buffer->has_more() && character_position++ < offset + length) {
uint16_t character = buffer->GetNext();
- if (character_position < offset + length) {
- if (allow_nulls == DISALLOW_NULLS && character == 0) {
- character = ' ';
- }
- utf8_byte_position +=
- unibrow::Utf8::Encode(result + utf8_byte_position, character);
- }
- character_position++;
+ if (allow_nulls == DISALLOW_NULLS && character == 0) {
+ character = ' ';
+ }
+ utf8_byte_position +=
+ unibrow::Utf8::Encode(result + utf8_byte_position, character);
}
result[utf8_byte_position] = 0;
return SmartArrayPointer<char>(result);
=======================================
--- /branches/bleeding_edge/src/profile-generator.cc Thu Nov 3 03:36:55
2011
+++ /branches/bleeding_edge/src/profile-generator.cc Wed Nov 9 04:15:35
2011
@@ -150,9 +150,11 @@
const char* StringsStorage::GetName(String* name) {
if (name->IsString()) {
- return AddOrDisposeString(
- name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL).Detach(),
- name->Hash());
+ int length = Min(kMaxNameSize, name->length());
+ SmartArrayPointer<char> data =
+ name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL, 0,
length);
+ uint32_t hash = HashSequentialString(*data, length);
+ return AddOrDisposeString(data.Detach(), hash);
}
return "";
}
=======================================
--- /branches/bleeding_edge/src/profile-generator.h Fri Oct 7 07:41:08 2011
+++ /branches/bleeding_edge/src/profile-generator.h Wed Nov 9 04:15:35 2011
@@ -74,6 +74,8 @@
inline const char* GetFunctionName(const char* name);
private:
+ static const int kMaxNameSize = 1024;
+
INLINE(static bool StringsMatch(void* key1, void* key2)) {
return strcmp(reinterpret_cast<char*>(key1),
reinterpret_cast<char*>(key2)) == 0;
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev