Closed Bug 627632 Opened 13 years ago Closed 13 years ago

Avoid silly malloc/realloc pattern in StringBuffer::finishString()

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: n.nethercote, Assigned: cdleary)

Details

(Whiteboard: fixed-in-tracemonkey)

Attachments

(1 file, 3 obsolete files)

Attached patch patch (obsolete) — Splinter Review
finishString() uses extractRawBuffer() on a vector.  It then reallocs (shrinks) the resulting buffer if it has empty space.  But it doesn't allow for the possibility that the jsvector has inline storage, in which case the extracted buffer will be malloc()'d to just the right size.

This patch fixes this.  It exposes usingInlineStorage(), which isn't great, but seems hard to avoid.

A simpler hack is to just increase sMinWasteSize to 100 or so, since inline storage is usually for smaller numbers of elements than that.  It's less exact though.

This avoids over 10,000 unnecessary reallocs in v8-regexp for a 1.003x instruction count win.
Attachment #505692 - Flags: review?(lw)
(In reply to comment #0)

Cool observation.

> A simpler hack is to just increase sMinWasteSize to 100 or so, since inline
> storage is usually for smaller numbers of elements than that.  It's less exact
> though.

This would've been my first approach.  The static type of CharBuffer tells you exactly its inline storage so, to be exact and clear about your intentions in the code, you could expose

  static const size_t MaxInlineStorage = N;

in js::Vector and then just use CharBuffer::MaxInlineStorage directly in StringBuffer::finishString instead of sMinWasteSize.
Eh, this doesn't seem worth the effort.  If anyone disagrees, please feel to reassign to yourself :)
Status: ASSIGNED → RESOLVED
Closed: 13 years ago
Resolution: --- → WONTFIX
Attachment #505692 - Flags: review?(luke)
Took a quick stab.
Assignee: nnethercote → cdleary
Attachment #505692 - Attachment is obsolete: true
Status: RESOLVED → REOPENED
Attachment #522878 - Flags: review?(luke)
Resolution: WONTFIX → ---
qref
Attachment #522878 - Attachment is obsolete: true
Attachment #522879 - Flags: review?(luke)
Attachment #522878 - Flags: review?(luke)
Man I suck at hg.
Attachment #522879 - Attachment is obsolete: true
Attachment #522880 - Flags: review?(luke)
Attachment #522879 - Flags: review?(luke)
Comment on attachment 522880 [details] [diff] [review]
Compare length against inline storage static.

The logic looks good.  I don't see any reason to tease out an extractWellSized() helper, though: it doesn't have any other callers and it doesn't seem to make sense as part of the StringBuffer interface. r+ with the extractWellSized function rolled into finishString or, if you'd like, an inline static helper.
Attachment #522880 - Flags: review?(luke) → review+
http://hg.mozilla.org/tracemonkey/rev/40d6f9795ecc

Talked to luke IRL and he agreed a private method helper makes sense here.
Status: REOPENED → ASSIGNED
Whiteboard: fixed-in-tracemonkey
http://hg.mozilla.org/mozilla-central/rev/40d6f9795ecc
Status: ASSIGNED → RESOLVED
Closed: 13 years ago13 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: