Changeset 59061 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
May 9, 2010, 2:16:16 PM (15 years ago)
Author:
[email protected]
Message:

Reserve a large-ish initial capacity for Lexer::m_buffer16.

Reviewed by Oliver Hunt.

SunSpider says 0.3% faster.

m_buffer16 is used when parsing complex strings -- for example, strings
with escape sequences in them. These kinds of strings can be really long,
and we want to avoid repeatedly copying as we grow m_buffer16.

The net memory cost is quite low, since it's proporitional to source
code we already have in memory, and we throw away m_buffer16 right when
we're done parsing.

  • parser/Lexer.cpp:

(JSC::Lexer::Lexer): No need to reserve initial capacity in our constructor,
since setCode will be called before we're asked to lex anything.
(JSC::Lexer::setCode): Reserve enough space to lex half the source code
as a complex string without having to copy.
(JSC::Lexer::clear): No need to reserve initial capacity here either,
since setCode will be called before we're asked to lex anything.

Location:
trunk/JavaScriptCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r59060 r59061  
     12010-05-09  Geoffrey Garen  <[email protected]>
     2
     3        Reviewed by Oliver Hunt.
     4
     5        Reserve a large-ish initial capacity for Lexer::m_buffer16.
     6       
     7        SunSpider says 0.3% faster.
     8       
     9        m_buffer16 is used when parsing complex strings -- for example, strings
     10        with escape sequences in them. These kinds of strings can be really long,
     11        and we want to avoid repeatedly copying as we grow m_buffer16.
     12       
     13        The net memory cost is quite low, since it's proporitional to source
     14        code we already have in memory, and we throw away m_buffer16 right when
     15        we're done parsing.
     16
     17        * parser/Lexer.cpp:
     18        (JSC::Lexer::Lexer): No need to reserve initial capacity in our constructor,
     19        since setCode will be called before we're asked to lex anything.
     20        (JSC::Lexer::setCode): Reserve enough space to lex half the source code
     21        as a complex string without having to copy.
     22        (JSC::Lexer::clear): No need to reserve initial capacity here either,
     23        since setCode will be called before we're asked to lex anything.
     24
    1252010-05-09  Laszlo Gombos  <[email protected]>
    226
  • trunk/JavaScriptCore/parser/Lexer.cpp

    r53224 r59061  
    5353    , m_keywordTable(JSC::mainTable)
    5454{
    55     m_buffer8.reserveInitialCapacity(initialReadBufferCapacity);
    56     m_buffer16.reserveInitialCapacity(initialReadBufferCapacity);
    5755}
    5856
     
    149147    m_error = false;
    150148    m_atLineStart = true;
     149
     150    m_buffer8.reserveInitialCapacity(initialReadBufferCapacity);
     151    m_buffer16.reserveInitialCapacity((m_codeEnd - m_code) / 2);
    151152
    152153    // ECMA-262 calls for stripping all Cf characters, but we only strip BOM characters.
     
    10101011
    10111012    Vector<char> newBuffer8;
    1012     newBuffer8.reserveInitialCapacity(initialReadBufferCapacity);
    10131013    m_buffer8.swap(newBuffer8);
    10141014
    10151015    Vector<UChar> newBuffer16;
    1016     newBuffer16.reserveInitialCapacity(initialReadBufferCapacity);
    10171016    m_buffer16.swap(newBuffer16);
    10181017
Note: See TracChangeset for help on using the changeset viewer.