Commit 65a25fed authored by Jakob Gruber's avatar Jakob Gruber Committed by Commit Bot

[regexp] Initially allocate the backtracking stack on the stack

Ideally, in the common case the backtracking stack should be
stack-allocated (and thus cheap). We should only switch to dynamic
allocation if needed. SmallVector implements exactly this strategy, so
switch to that as a backing store.

This improves Octane/RegExp scores (--regexp-interpret-all) by 50%.

Bug: v8:7777,v8:9330
Change-Id: I0d1b07bd8fd94483128e021390d054f483076f8d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1645318
Auto-Submit: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62013}
parent b1072142
......@@ -88,6 +88,10 @@ class SmallVector {
DCHECK_NE(0, size());
return end_[-1];
}
const T& back() const {
DCHECK_NE(0, size());
return end_[-1];
}
T& operator[](size_t index) {
DCHECK_GT(size(), index);
......
......@@ -7,6 +7,7 @@
#include "src/regexp/interpreter-irregexp.h"
#include "src/ast/ast.h"
#include "src/base/small-vector.h"
#include "src/objects/objects-inl.h"
#include "src/regexp/bytecodes-irregexp.h"
#include "src/regexp/jsregexp.h"
......@@ -138,11 +139,15 @@ class BacktrackStack {
int sp() const { return static_cast<int>(data_.size()); }
void set_sp(int new_sp) {
DCHECK_LE(new_sp, sp());
data_.resize(new_sp);
data_.resize_no_init(new_sp);
}
private:
std::vector<int> data_;
// Semi-arbitrary. Should be large enough for common cases to remain in the
// static stack-allocated backing store, but small enough not to waste space.
static constexpr int kStaticCapacity = 64;
base::SmallVector<int, kStaticCapacity> data_;
DISALLOW_COPY_AND_ASSIGN(BacktrackStack);
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment