Re: TextView question
Re: TextView question
- Subject: Re: TextView question
- From: Spencer Salazar <email@hidden>
- Date: Fri, 11 Aug 2006 08:57:49 -0400
Not sure if you tried this already, but I use [[logView2 textStorage]
appendAttributedString:myString]; When I switched to that (from
NSTextView's appendString:) I got a huge speed increase, up to about
20000 chars/500 lines per second (with scrolling to the end).
Also, if Im not mistaken, this line: NSString *newText = [theText
stringByAppendingString:@"\n"]; will copy the entirety of theText
into the new NSString, which can be really time consuming in a tight
loop. Why not first append theText to your TextView (or
TextStorage), and then append a newline to the TextView (as the
TextView/TextStorage is more likely to be optimized for that sort of
thing than a String).
spencer
On Aug 10, 2006, at 11:48 PM, Jason Jasmin wrote:
On Aug 10, 2006, at 3:42 PM, Andreas Mayer wrote:
What is "relatively slow" and what exactly (show some code!) did
you try?
Sorry, I should have been more specific earlier... My problem is
that in my code, for each loop iteration, I call NSLog twice, and
write one line of output to my log window. If I disable all output
to my log window, and just leave the NSLog calls, the app runs very
quickly (on the order of 5 seconds or so). I can see the NSLog
entries in XCode flying by quickly. When I enable output to my
logging window, the app slows down dramatically, taking > 20
seconds to run.
Normally this wouldn't be a huge problem (I don't expect there to
be that much output in production), but it's annoying because the
XCode run log proves that the output can be a lot faster than it is.
I've looked around the net for various "high performance" text
solutions, and none of them are apparently any faster than what I
had originally. Here's what I've got right now, it's the simplest
text update code I could come up with:
NSRange range = NSMakeRange([[logView2 string] length], 0);
NSString *newText = [theText stringByAppendingString:@"\n"];
[logView2 replaceCharactersInRange:range withString:newText];
[logView2 scrollRangeToVisible:range];
Now if I comment the last line out (the scrollRangeToVisible) then
it runs fast enough for me (it seems a little slower than with the
entire logging function disabled, but it's in the same ballpark as
XCode -- close enough).
I've tried a few variations on that code, caching the length of the
text to avoid calling NSString:length and so forth, but nothing
makes any significant difference
Jason
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40gmail.com
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden