Dimi Paun,
It could be the slowdown is due to the "in-line" RegExp in the trim().

I always keep these pre-compiled in an external variable for speed
(cached).

Since you are going to try, I would suggest that as the first try.
Next try would be also to avoid a call to trim() and just do it in-
line there (in the clean() method) and see if this improve the
speed...and how much...I bet there is quite an improvement, don't know
if it is enough for the OP...wow 660Kb...

First declare externally the used RegExp some place (another tip, is
the /g global flag necessary ? if not it will also be part of the slow
down):

var trim = /^\s+|\s+$/g,

then in clean() line 868 (in 1.3.1):

   // Trim whitespace, otherwise indexOf won't work as expected
   var tags = elem.replace(trim, '').toLowerCase();

I would then try to only do the left part as you suggested, believe
that's enough too.

I haven't tested any of the above just trying to help spot the
problem, I know some is already doing the tests....


Diego


On 31 Gen, 16:16, Dimi Paun <[email protected]> wrote:
> Thanks. But we can do better still:
>   1. it seems that the slow part for trimming is trimming
>      spaces at the *end* which is rather irrelevant here.
>   2. in fact, we don't need _any_ trimming here, we could
>      just have a reg exp that matches the begging and
>      ignores leading spaces.
>
> Of course, (2) is more work/code than (1). I'll give them
> a try and report back.
>
>
>
> On Sat, 2009-01-31 at 04:08 -0800, Ariel Flesler wrote:
> >http://dev.jquery.com/ticket/2279#comment:7
>
> > --
> > Ariel Flesler
> >http://flesler.blogspot.com
>
> > On 30 ene, 22:02, dimi <[email protected]> wrote:
> > > Hi folks,
>
> > > I have a large HTML fragment that I load via AJAX. The fragment is big
> > > (~660KB),
> > > and it takes over 2s (more like 2.7s) to insert it.
>
> > > I've profiled the code, and it turns out that most of the time is
> > > spent in the .trim()
> > > function. It is being called from .clean() (around line 835):
>
> > >                                 // Trim whitespace, otherwise indexOf 
> > > won't work as expected
> > >                                 var tags = jQuery.trim( elem 
> > > ).toLowerCase();
>
> > > Is this something that can be fixed?
>
> > > Dimi.
> > --
>
> Dimi Paun <[email protected]>
> Lattica, Inc.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to