1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-30 21:58:10 +00:00
serenity/Userland/Libraries/LibJS
Andreas Kling b0b022507b LibJS: Reduce AST memory usage by shrink-wrapping source range info
Before this change, each AST node had a 64-byte SourceRange member.
This SourceRange had the following layout:

    filename:       StringView (16 bytes)
    start:          Position (24 bytes)
    end:            Position (24 bytes)

The Position structs have { line, column, offset }, all members size_t.

To reduce memory consumption, AST nodes now only store the following:

    source_code:    NonnullRefPtr<SourceCode> (8 bytes)
    start_offset:   u32 (4 bytes)
    end_offset:     u32 (4 bytes)

SourceCode is a new ref-counted data structure that keeps the filename
and original parsed source code in a single location, and all AST nodes
have a pointer to it.

The start_offset and end_offset can be turned into (line, column) when
necessary by calling SourceCode::range_from_offsets(). This will walk
the source code string and compute line/column numbers on the fly, so
it's not necessarily fast, but it should be rare since this information
is primarily used for diagnostics and exception stack traces.

With this, ASTNode shrinks from 80 bytes to 32 bytes. This gives us a
~23% reduction in memory usage when loading twitter.com/awesomekling
(330 MiB before, 253 MiB after!) :^)
2022-11-22 21:13:35 +01:00
..
Bytecode LibJS: Teach GetVariable bytecode op to deal with global variable cache 2022-11-11 15:25:52 +01:00
Contrib/Test262 LibJS: Implement $262.evalScript() according to the given algorithm 2022-08-30 12:00:04 +01:00
Heap LibJS+LibWeb: Return non-const types from Ptr class operators 2022-11-19 14:37:31 +00:00
Runtime LibJS: Reduce AST memory usage by shrink-wrapping source range info 2022-11-22 21:13:35 +01:00
Tests LibJS: Fix UTF-16 corruption in String.prototype.replace() 2022-11-19 11:30:06 -07:00
AST.cpp LibJS: Reduce AST memory usage by shrink-wrapping source range info 2022-11-22 21:13:35 +01:00
AST.h LibJS: Reduce AST memory usage by shrink-wrapping source range info 2022-11-22 21:13:35 +01:00
CMakeLists.txt LibJS: Reduce AST memory usage by shrink-wrapping source range info 2022-11-22 21:13:35 +01:00
Console.cpp LibJS+js: Disable console debug messages outside Serenity only for js 2022-10-16 02:06:02 +03:30
Console.h LibJS+js: Disable console debug messages outside Serenity only for js 2022-10-16 02:06:02 +03:30
CyclicModule.cpp LibJS: Add [[HostDefined]] field to Modules 2022-10-06 16:41:36 +02:00
CyclicModule.h LibJS: Add accessor for requested modules to CyclicModule 2022-10-06 16:41:36 +02:00
Forward.h LibJS: Reduce AST memory usage by shrink-wrapping source range info 2022-11-22 21:13:35 +01:00
Interpreter.cpp LibJS: Make Script and Module GC-allocated 2022-09-06 00:27:09 +02:00
Interpreter.h LibJS: Remove {Bytecode::,}Interpreter::global_object() 2022-08-23 13:58:30 +01:00
Lexer.cpp LibJS: Treat '\\' as an escaped character in template literals 2022-11-15 12:00:36 +00:00
Lexer.h LibJS: Reduce AST memory usage by shrink-wrapping source range info 2022-11-22 21:13:35 +01:00
MarkupGenerator.cpp LibJS: Reduce AST memory usage by shrink-wrapping source range info 2022-11-22 21:13:35 +01:00
MarkupGenerator.h WebContent+LibWeb+LibJS: Report exceptions to the JS console 2022-10-15 01:25:12 +02:00
Module.cpp LibJS: Add [[HostDefined]] field to Modules 2022-10-06 16:41:36 +02:00
Module.h LibJS: Add [[HostDefined]] field to Modules 2022-10-06 16:41:36 +02:00
Parser.cpp LibJS: Reduce AST memory usage by shrink-wrapping source range info 2022-11-22 21:13:35 +01:00
Parser.h LibJS: Reduce AST memory usage by shrink-wrapping source range info 2022-11-22 21:13:35 +01:00
SafeFunction.h LibJS: Don't register SafeFunction-to-function-pointer with JS::Heap 2022-10-20 15:16:23 +02:00
Script.cpp LibJS: Make sure JS::Script visits its HostDefined object 2022-09-06 01:21:09 +02:00
Script.h LibJS: Mark [[HostDefined]] accessor on scripts as const 2022-10-06 16:41:36 +02:00
SourceCode.cpp LibJS: Reduce AST memory usage by shrink-wrapping source range info 2022-11-22 21:13:35 +01:00
SourceCode.h LibJS: Reduce AST memory usage by shrink-wrapping source range info 2022-11-22 21:13:35 +01:00
SourceRange.h LibJS: Reduce AST memory usage by shrink-wrapping source range info 2022-11-22 21:13:35 +01:00
SourceTextModule.cpp LibJS: Add [[HostDefined]] field to Modules 2022-10-06 16:41:36 +02:00
SourceTextModule.h LibJS: Add [[HostDefined]] field to Modules 2022-10-06 16:41:36 +02:00
SyntaxHighlighter.cpp LibJS: Remove a bunch of gratuitous JS namespace qualifiers 2022-04-03 15:19:33 +01:00
SyntaxHighlighter.h Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
SyntheticModule.cpp LibJS: Make Script and Module GC-allocated 2022-09-06 00:27:09 +02:00
SyntheticModule.h LibJS: Make Script and Module GC-allocated 2022-09-06 00:27:09 +02:00
Token.cpp LibJS: Make Token use the new double parser 2022-10-23 15:48:45 +02:00
Token.h Everywhere: Explicitly specify the size in StringView constructors 2022-07-12 23:11:35 +02:00