forked from svaarala/duktape
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemoryusage.html
More file actions
41 lines (35 loc) · 2.37 KB
/
memoryusage.html
File metadata and controls
41 lines (35 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<h1 id="memoryusage">Memory usage</h1>
<p>Duktape allocates memory on demand and doesn't require a pre-allocated heap.
When you create a heap on a 32-bit system, Duktape needs about 80kB for the
built-in ECMAScript objects. With specific
<a href="#memory-constrained-options">low memory options</a> initial memory
usage is about 27kB. This can be further reduced to about 3kB when moving
built-in objects and strings to ROM (read-only data section). It's also
possible to move custom native bindings fully into ROM.</p>
<p>After heap creation additional memory is then allocated as needed for
executing application scripts. Reference counting ensures there is very
little unused allocated memory, the only major exception being objects which
participate in reference loops; these are collected eventually by mark-and-sweep.</p>
<p>The memory allocations needed by Duktape fall into two basic categories.
First, there are a lot of small allocations between roughly 16 to 128 bytes
which are needed for strings, buffers, objects, object property tables, etc.
Second, there are much fewer larger allocations needed for e.g. ECMAScript
function bytecode, large strings and buffers, value stacks, the global string
table, and the Duktape heap object.</p>
<p>For most systems memory usage or the memory allocation pattern is not an
issue. On low memory environments, e.g. less than 1MB of system RAM, you may
want to use a custom allocator to optimize memory usage. A pool-based
allocator deals well with the small allocation churn without fragmentation
issues. The downside is that you need to tune the memory pool sizes to match
the concrete allocation patterns. You may want to use a pool allocator or a
hybrid allocated if the platform allocation primitives perform poorly with
a lot of small allocations.</p>
<p>See <a href="#memory-constrained-options">low memory options</a> and
<a href="https://github.com/svaarala/duktape/blob/master/doc/low-memory.rst">low-memory.rst</a>
for more discussion on what low memory features exists and how to tune the
memory pools for low memory systems.</p>
<p>With default options Duktape uses a 32-bit refcount field which may
technically wrap on 64-bit systems with very large memory sizes. In
practice this is unlikely to happen and requires the Duktape heap to be
larger than 64GB. Disable <code>DUK_USE_REFCOUNT32</code> to use
<code>size_t</code> for refcount fields.</p>