Ignore:
Timestamp:
Feb 6, 2007, 11:42:35 AM (18 years ago)
Author:
darin
Message:

Reviewed by John.

  • fix <rdar://problem/4687840> 9A241: JavaScript RegExp 25-30x slower than on 10.4.7

I used Shark to figure out what to do. The test case is now 15% faster than with
stock Safari. Some other regular expression cases might still be a few % slower
than before, but the >10x slowdown is now completely gone.

1) Fix slowness caused by setjmp/longjmp by using computed goto instead.

Use GCC extensions - locally declared labels, labels as values, and computed goto -
instead of using setjmp/longjmp to implemement non-recursive version of the regular
expression system. We could probably make this even faster if we reduced the use
of malloc a bit too.

2) Fix slowness caused by allocating heapframe objects by allocating the first

16 of them from the stack.

3) Speed up use of malloc and free in PCRE by making it use fastMalloc and fastFree.

4) Speed up the test case by adding a special case to a UString function.

5) Made a small improvement to the innermost hottest loop of match by hoisting

the conversion from int to pcre_uchar out of the loop.

  • JavaScriptCore.xcodeproj/project.pbxproj: Compile FastMallocPCRE.cpp, and don't compile pcre_globals.c.
  • wtf/FastMallocPCRE.cpp: Added. A copy of pcre_globals.c that uses FastMalloc.h. This is better than code that sets the PCRE allocation globals because by doing it this way there's guaranteed to be no problem with order of initialization.
  • kjs/ustring.cpp: (KJS::UString::spliceSubstringsWithSeparators): Add a fast special case when this is called for only one subrange and no seaprators. This was happening a lot in the test case and it seems quite reasonable to optimize this.
  • pcre/pcre_exec.c: Create a copy of the RMATCH and RRETURN macros that use goto instead of setjmp/longjmp. Change code that calls pcre_stack_malloc to first use storage on the stack inside the match function. (match): Move initialization of utf8 up a couple lines to avoid "possibly used uninitialized" warning. Use a local variable so we compare with pcre_uchar instead of with int inside the inner "find a character" loop.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj

    r19302 r19434  
    120120                65FB3F5109D11B2400F49DEB /* grammar.h in Headers */ = {isa = PBXBuildFile; fileRef = 65FB3F4909D11B2400F49DEB /* grammar.h */; };
    121121                65FB3F5409D11B2400F49DEB /* regexp_object.lut.h in Headers */ = {isa = PBXBuildFile; fileRef = 65FB3F4C09D11B2400F49DEB /* regexp_object.lut.h */; };
     122                9302043B0B790750000C6115 /* FastMallocPCRE.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9302043A0B790750000C6115 /* FastMallocPCRE.cpp */; };
    122123                9303F568099118FA00AD71B8 /* OwnPtr.h in Headers */ = {isa = PBXBuildFile; fileRef = 9303F567099118FA00AD71B8 /* OwnPtr.h */; settings = {ATTRIBUTES = (Private, ); }; };
    123124                9303F56A0991190000AD71B8 /* Noncopyable.h in Headers */ = {isa = PBXBuildFile; fileRef = 9303F5690991190000AD71B8 /* Noncopyable.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    125126                930754C108B0F68000AB3056 /* pcre_compile.c in Sources */ = {isa = PBXBuildFile; fileRef = 930754BF08B0F68000AB3056 /* pcre_compile.c */; };
    126127                930754D008B0F74600AB3056 /* pcre_tables.c in Sources */ = {isa = PBXBuildFile; fileRef = 930754CE08B0F74500AB3056 /* pcre_tables.c */; };
    127                 930754D308B0F76300AB3056 /* pcre_globals.c in Sources */ = {isa = PBXBuildFile; fileRef = 930754D108B0F76200AB3056 /* pcre_globals.c */; };
    128128                930754E808B0F77700AB3056 /* pcre_fullinfo.c in Sources */ = {isa = PBXBuildFile; fileRef = 930754E608B0F77700AB3056 /* pcre_fullinfo.c */; };
    129129                930754EB08B0F78500AB3056 /* pcre_exec.c in Sources */ = {isa = PBXBuildFile; fileRef = 930754E908B0F78500AB3056 /* pcre_exec.c */; };
     
    566566                70B16A270569A10900DB756D /* runtime_object.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; name = runtime_object.h; path = bindings/runtime_object.h; sourceTree = "<group>"; tabWidth = 8; };
    567567                84ABF1DE070B628C00A3AC05 /* npruntime_impl.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; name = npruntime_impl.h; path = bindings/npruntime_impl.h; sourceTree = "<group>"; tabWidth = 8; };
     568                9302043A0B790750000C6115 /* FastMallocPCRE.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FastMallocPCRE.cpp; sourceTree = "<group>"; };
    568569                9303F567099118FA00AD71B8 /* OwnPtr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OwnPtr.h; sourceTree = "<group>"; };
    569570                9303F5690991190000AD71B8 /* Noncopyable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Noncopyable.h; sourceTree = "<group>"; };
     
    571572                930754BF08B0F68000AB3056 /* pcre_compile.c */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.c; name = pcre_compile.c; path = pcre/pcre_compile.c; sourceTree = "<group>"; tabWidth = 8; };
    572573                930754CE08B0F74500AB3056 /* pcre_tables.c */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.c; name = pcre_tables.c; path = pcre/pcre_tables.c; sourceTree = "<group>"; tabWidth = 8; };
    573                 930754D108B0F76200AB3056 /* pcre_globals.c */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.c; name = pcre_globals.c; path = pcre/pcre_globals.c; sourceTree = "<group>"; tabWidth = 8; };
    574574                930754E608B0F77700AB3056 /* pcre_fullinfo.c */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.c; name = pcre_fullinfo.c; path = pcre/pcre_fullinfo.c; sourceTree = "<group>"; tabWidth = 8; };
    575575                930754E908B0F78500AB3056 /* pcre_exec.c */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.c; name = pcre_exec.c; path = pcre/pcre_exec.c; sourceTree = "<group>"; tabWidth = 8; };
     
    890890                        isa = PBXGroup;
    891891                        children = (
    892                                 657EB7450B708F540063461B /* ListHashSet.h */,
    893892                                E195678D09E7CF1200B89D13 /* unicode */,
    894893                                93AA4F770957251F0084B3A7 /* AlwaysInline.h */,
     
    898897                                65E217BA08E7EECC0023E5F6 /* FastMalloc.h */,
    899898                                65D7D19B08F10B5B0015ABD8 /* FastMallocInternal.h */,
     899                                9302043A0B790750000C6115 /* FastMallocPCRE.cpp */,
    900900                                935AF46909E9D9DB00ACD1D8 /* Forward.h */,
    901901                                93B6A0DE0AA64DA40076DE27 /* GetPtr.h */,
     
    907907                                65DFC92E08EA173A00F7300B /* HashTable.h */,
    908908                                65DFC92F08EA173A00F7300B /* HashTraits.h */,
     909                                657EB7450B708F540063461B /* ListHashSet.h */,
    909910                                148A1626095D16BB00666D0D /* ListRefPtr.h */,
    910911                                BCF6553B0A2048DE0038A194 /* MathExtras.h */,
     
    10311032                                930754E608B0F77700AB3056 /* pcre_fullinfo.c */,
    10321033                                93E26CF608B29A1C00F85226 /* pcre_get.c */,
    1033                                 930754D108B0F76200AB3056 /* pcre_globals.c */,
    10341034                                93E26BE508B1517100F85226 /* pcre_internal.h */,
    10351035                                93E26BC908B1511900F85226 /* pcre_ord2utf8.c */,
     
    14921492                                930754C108B0F68000AB3056 /* pcre_compile.c in Sources */,
    14931493                                930754D008B0F74600AB3056 /* pcre_tables.c in Sources */,
    1494                                 930754D308B0F76300AB3056 /* pcre_globals.c in Sources */,
    14951494                                930754E808B0F77700AB3056 /* pcre_fullinfo.c in Sources */,
    14961495                                930754EB08B0F78500AB3056 /* pcre_exec.c in Sources */,
     
    15231522                                D212022A0AD4310D00ED79B6 /* DateMath.cpp in Sources */,
    15241523                                146AAB380B66A94400E55F16 /* JSStringRefCF.cpp in Sources */,
     1524                                9302043B0B790750000C6115 /* FastMallocPCRE.cpp in Sources */,
    15251525                        );
    15261526                        runOnlyForDeploymentPostprocessing = 0;
Note: See TracChangeset for help on using the changeset viewer.