The default bug view has changed. See this FAQ.

Create TraceMonitors lazily

RESOLVED FIXED

Status

()

Core
JavaScript Engine
RESOLVED FIXED
6 years ago
6 years ago

People

(Reporter: njn, Assigned: njn)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [MemShrink:P2][fixed-in-tracemonkey])

Attachments

(1 attachment)

(Assignee)

Description

6 years ago
When a JaegerCompartment is created, it always generates some code immediately in the TrampolineCompiler, which involves mapping 64KB of executable memory (64KB is the minimum code chunk size).

This shouldn't be necessary for atomsCompartment.  It should be easy to add a boolean flag |hasCode| somewhere to JaegerCompartment and avoid this for atomsCompartment.  A small win but an easy one.
(Assignee)

Comment 1

6 years ago
We're also allocating 186,000 bytes worth of space for trace JIT data, which is unnecessary for the atomsCompartment.  And probably a bit more for various heap allocations done in TraceMonitor::init().  We should avoid that too.
(Assignee)

Updated

6 years ago
Summary: atomsCompartment doesn't need a JaegerCompartment → atomsCompartment doesn't need a JaegerCompartment or a TraceMonitor
(Assignee)

Comment 2

6 years ago
This idea can be extended.  Some compartments have tiny amounts of JS code in them which never gets method JITted and/or trace JITted (eg. techcrunch.com's front page has dozens of them).  Doing lazy initialization/allocation of the relevant code and data chunks could save quite a bit of space.
Summary: atomsCompartment doesn't need a JaegerCompartment or a TraceMonitor → atomsCompartment doesn't need a JaegerCompartment or a TraceMonitor, nor do some other compartments
Whiteboard: [MemShrink:P2]
(Assignee)

Updated

6 years ago
Summary: atomsCompartment doesn't need a JaegerCompartment or a TraceMonitor, nor do some other compartments → Create JaegerCompartments and TraceMonitors lazily

Comment 3

6 years ago
Thanks for pointing me to this Nick.  bug 650411 should help a lot since both in theory can be hoisted to the (single-threaded) JSRuntime (which should be very few in number).
(Assignee)

Comment 4

6 years ago
(In reply to comment #3)
> Thanks for pointing me to this Nick.  bug 650411 should help a lot since
> both in theory can be hoisted to the (single-threaded) JSRuntime (which
> should be very few in number).

The entire JaegerCompartment and TraceMonitor could be hoisted?  That'd be very nice.

Comment 5

6 years ago
Yep (the comment for JaegerCompartment explains that all it wants is single-threadedness).
(Assignee)

Comment 6

6 years ago
Luke, it sounds like a single-threaded JSRuntime won't happen soon.  Assuming that's right, I'll go ahead with this bug, because my per-compartments patch for about:memory shows that it's really easy to get dozens and dozens of tiny compartments, and the thought of wasting 0.25MB on each one is giving me an ulcer.
(Assignee)

Comment 7

6 years ago
Created attachment 540002 [details] [diff] [review]
make TraceMonitor lazy

This patch does the TraceMonitor.  Here's an example from about:memory:

│  └──────65,536 B (00.14%) -- compartment(atoms)
│         ├──65,536 B (00.14%) -- mjit-code
│         ├───────0 B (00.00%) -- scripts
│         ├───────0 B (00.00%) -- mjit-data
│         ├───────0 B (00.00%) -- tjit-code
│         └───────0 B (00.00%) -- tjit-data
│                 ├──0 B (00.00%) -- allocators-main
│                 └──0 B (00.00%) -- allocators-reserve

186,000 bytes down, 65,536 to go.  I'll do the patch for the JaegerCompartment on Monday.
Attachment #540002 - Flags: review?(luke)
(Assignee)

Comment 8

6 years ago
(In reply to comment #7)
> 
> 186,000 bytes down

Actually, on 64-bit it's more like 256KB because there are various other things (most notably the TraceNativeStorage) in the TraceMonitor that aren't captured in the memory reporters.  On 32-bit it's a bit less.

Comment 9

6 years ago
Comment on attachment 540002 [details] [diff] [review]
make TraceMonitor lazy

Nice; ulcers are bad.
Attachment #540002 - Flags: review?(luke) → review+
(Assignee)

Updated

6 years ago
Summary: Create JaegerCompartments and TraceMonitors lazily → Create TraceMonitors lazily
(Assignee)

Updated

6 years ago
Blocks: 665404
(Assignee)

Comment 10

6 years ago
I've narrowed the focus of this bug just to TraceMonitor;  JaegerCompartment is now covered by bug 665404.
No longer blocks: 665404
(Assignee)

Comment 11

6 years ago
Landed with a follow-up to fix some --disable-tracejit bustage:

http://hg.mozilla.org/tracemonkey/rev/1e464e38591e
http://hg.mozilla.org/tracemonkey/rev/57ef3b619966
Whiteboard: [MemShrink:P2] → [MemShrink:P2][fixed-on-tracemonkey]
cdleary-bot mozilla-central merge info:
http://hg.mozilla.org/mozilla-central/rev/1e464e38591e
http://hg.mozilla.org/mozilla-central/rev/57ef3b619966
Note: not marking as fixed because fixed-in-tracemonkey is not present on the whiteboard.
Status: ASSIGNED → RESOLVED
Last Resolved: 6 years ago
Resolution: --- → FIXED
Whiteboard: [MemShrink:P2][fixed-on-tracemonkey] → [MemShrink:P2][fixed-in-tracemonkey]
You need to log in before you can comment on or make changes to this bug.