Closed
Bug 587884
Opened 15 years ago
Closed 15 years ago
Optimize PrintWriter print() for String class
Categories
(Tamarin Graveyard :: Virtual Machine, defect)
Tamarin Graveyard
Virtual Machine
Tracking
(Not tracked)
RESOLVED
FIXED
People
(Reporter: rreitmai, Unassigned)
References
Details
Attachments
(1 file, 2 obsolete files)
4.80 KB,
patch
|
edwsmith
:
review+
|
Details | Diff | Splinter Review |
String::print(PrintWriter& p) calls p.writeN() which copies the string contents into a buffer, null terminates it and then calls write() on it.
StringOutputStream then calls writeN() computing a length for the string and again copies it into a final buffer.
This whole sequence could be optimized by allowing OutputStream a writeN() method, avoiding the copying and multiple length computations.
Reporter | ||
Updated•15 years ago
|
Attachment #466500 -
Attachment is patch: true
Attachment #466500 -
Attachment mime type: application/octet-stream → text/plain
Attachment #466500 -
Flags: review?(edwsmith)
Comment 1•15 years ago
|
||
Comment on attachment 466500 [details] [diff] [review]
add writeN()
nit: please preserve exiting comment formatting that uses // instead of /* */
Since the new ConsoleOutputStream field m_buffer (a StringBuffer) is only used transiently, must it be a member?
Also, I'm suspicious about it being a GCObject member of annother GCObject -- will its internal write barriers find the start of the outermost GCObject?
(not this bug, but the whole OutputStream class heirarchy seems rife with GC pain).
Comment 2•15 years ago
|
||
Comment on attachment 466500 [details] [diff] [review]
add writeN()
R- because of the m_buffer declaration; StringBuffer extends GCObject so it can't be a member of another GCObject. (existing cases of this are considered bugs).
Attachment #466500 -
Flags: review?(edwsmith) → review-
Reporter | ||
Comment 3•15 years ago
|
||
Addressed comments. The StringBuffer is kept around since it will be used throughout the lifetime of the ConsoleOutputStream. We could keep building it each call to writeN() but that seems wasteful.
Attachment #466500 -
Attachment is obsolete: true
Attachment #467609 -
Flags: review?(edwsmith)
Comment 4•15 years ago
|
||
Comment on attachment 467609 [details] [diff] [review]
ver 2
ConsoleOutputStream:53 I'm sorry to R- again, but in avoiding MMgc pitfall #27-part-b, you managed to fall into MMgc pitfall #1: missing write barrier. You need a WB() around the assignment, or a DWB() around the StringBuffer* declaration.
Could you punctuate and clarify the comment "careful with this it usually results in a copy by the stream" -- what does "usually" mean? what does being careful entail?
It looks like the new buffer member will grow to be as big as the largest single stream we ever print, and never shrink. That ok?
Updated•15 years ago
|
Attachment #467609 -
Flags: review?(edwsmith) → review-
Reporter | ||
Comment 5•15 years ago
|
||
Three times lucky?
Big oops; added DWB()
>> It looks like the new buffer member will grow to be as big as the largest
single stream we ever print, and never shrink. That ok?
I believe it should be fine as it will only grow as large as 'count' of a single call to writeN(). After logMessage(), m_buffer->reset() is called which prevents unbounded growth.
Attachment #467609 -
Attachment is obsolete: true
Attachment #467822 -
Flags: review?(edwsmith)
Comment 6•15 years ago
|
||
Comment on attachment 467822 [details] [diff] [review]
ver3
Much better comment, thank you!
Attachment #467822 -
Flags: review?(edwsmith) → review+
Reporter | ||
Comment 7•15 years ago
|
||
Status: NEW → RESOLVED
Closed: 15 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•