mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 19:08:10 +00:00
LibJS: Make line-and-column resolution fast for large minified JS
Instead of caching start-of-line offsets, we now cache byte offsets at regular intervals. This fixes an issue where we had terrible performance on large minified JS, since that often means one very, VERY long line (with no line endings to cache). My machine was spending ~35ms per stack frame when throwing errors on some heavy minified websites, and after this patch, we now spend <1ms per stack frame.
This commit is contained in:
parent
ff02de4ad0
commit
44b2735b9e
4 changed files with 67 additions and 35 deletions
|
@ -9,6 +9,7 @@
|
|||
#include <AK/String.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibJS/Forward.h>
|
||||
#include <LibJS/Position.h>
|
||||
|
||||
namespace JS {
|
||||
|
||||
|
@ -24,12 +25,14 @@ public:
|
|||
private:
|
||||
SourceCode(String filename, String code);
|
||||
|
||||
void compute_line_break_offsets() const;
|
||||
|
||||
String m_filename;
|
||||
String m_code;
|
||||
|
||||
Optional<Vector<size_t>> mutable m_line_break_offsets;
|
||||
// For fast mapping of offsets to line/column numbers, we build a list of
|
||||
// starting points (with byte offsets into the source string) and which
|
||||
// line:column they map to. This can then be binary-searched.
|
||||
void fill_position_cache() const;
|
||||
Vector<Position> mutable m_cached_positions;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue