• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Speed Traps
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Speed Traps


  • Subject: Re: Speed Traps
  • From: David Remahl <email@hidden>
  • Date: Thu, 15 May 2003 00:22:38 +0200

I spent a day rewriting a custom expression parcer for what I hoped would give me much more speed but the final result is now slower. It is hard to believe it is slower; could I be missing some Cocoa speed traps?

First version parced a NSString expression and evaluated as it went.

New version tokenizes the expression on the first past and then all subsequent passes do no parcing, but just evaluate using the tokens. The new version evaluation with tokens is slower than the first version that parced AND evaluated on every pass. It does not make sense and I am hoping I missed something or am using some Cocoa feature in new version that is cause speed hang up?

One finding and maybe clue to speed traps:

In evaluating from tokens for expressions with groupings, I recursive pass sub arrays of tokens to a function. If I allocate the sub arrays and release them it it is slower than using autoreleased arrays. In other words

subExpr=[[NSMutableArray alloc] initWithArray:...]
evaluate
[subExpr release];

is noticeably slower than

subExpr=[NSMutableArray arrayWithArray:...]
evaluate

I used the former method because I was concerned this large calculation would be building up a large pool of autoreleased objects (several hundred thousand) and slowing things down. I guess that was wrong.

While I can't comment on your main question, I believe I can give an explanation why method two is faster than method one.

As you probably know, NSArrays are implemented as class clusters. That means that objects of different classes may be returned depending on what sort of data they contain. They way it works, is that [NSMutableArray alloc] returns one object, which is then replaced by another one when the initWithArray: method is called. The first allocation is then useless, and it is released.

NSMutableArray most likely implements arrayWithArray: more efficiently, since it already at the time of the first allocation knows what data will be contained in the array. It can thereby avoid a few steps, and create the correct object straight ahead.

/ Rgds, David
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Speed Traps (From: John Nairn <email@hidden>)

  • Prev by Date: Speed Traps
  • Next by Date: [<object> class] crash
  • Previous by thread: Speed Traps
  • Next by thread: Re: Speed Traps
  • Index(es):
    • Date
    • Thread