Skip to content

Commit

Permalink
Merge pull request #59 from gwenn/ector-perf-improv
Browse files Browse the repository at this point in the history
Remove SmallVec
  • Loading branch information
gwenn authored Jul 20, 2024
2 parents dfc680c + f83a162 commit 5bf0aa7
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 76 deletions.
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ maintenance = { status = "experimental" }
# FIXME: specific to one parser, not global
YYTRACKMAXSTACKDEPTH = []
YYNOERRORRECOVERY = []
YYSTACKDYNAMIC = []
YYCOVERAGE = []
NDEBUG = []
default = ["YYNOERRORRECOVERY"]
Expand All @@ -29,7 +28,6 @@ phf = { version = "0.11", features = ["uncased"] }
log = "0.4"
memchr = "2.0"
fallible-iterator = "0.3"
smallvec = ">=1.6.1"
bitflags = "2.0"
uncased = "0.9"
indexmap = "2.0"
Expand Down
12 changes: 6 additions & 6 deletions sqlparser_bench/benches/sqlparser_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ fn basic_queries(c: &mut Criterion) {
let mut group = c.benchmark_group("sqlparser-rs parsing benchmark");

let string = b"SELECT * FROM `table` WHERE 1 = 1";
group.bench_function("sqlparser::select", |b| {
group.bench_with_input("sqlparser::select", &string, |b, &s| {
b.iter(|| {
let mut parser = Parser::new(string);
parser.next()
let mut parser = Parser::new(s);
assert!(parser.next().unwrap().unwrap().readonly())
});
});

Expand All @@ -36,10 +36,10 @@ fn basic_queries(c: &mut Criterion) {
SELECT * FROM `table`
LEFT JOIN derived USING (user_id)
";
group.bench_function("sqlparser::with_select", |b| {
group.bench_with_input("sqlparser::with_select", &with_query, |b, &s| {
b.iter(|| {
let mut parser = Parser::new(with_query);
parser.next()
let mut parser = Parser::new(s);
assert!(parser.next().unwrap().unwrap().readonly())
});
});
}
Expand Down
3 changes: 0 additions & 3 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ use ast::{Cmd, ExplainKind, Name, Stmt};
/// Parser error
#[derive(Debug, PartialEq)]
pub enum ParserError {
/// Stack overflow
StackOverflow,
/// Syntax error
SyntaxError {
/// token type
Expand All @@ -38,7 +36,6 @@ pub enum ParserError {
impl std::fmt::Display for ParserError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
ParserError::StackOverflow => f.write_str("parser overflowed its stack"),
ParserError::SyntaxError { token_type, found } => {
write!(f, "near {}, \"{:?}\": syntax error", token_type, found)
}
Expand Down
4 changes: 0 additions & 4 deletions src/parser/parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@
});
}
}
%stack_overflow {
error!(target: TARGET, "parser stack overflow");
self.ctx.error = Some(ParserError::StackOverflow);
}

// The name of the generated procedure that implements the parser
// is as follows:
Expand Down
2 changes: 0 additions & 2 deletions third_party/lemon/lemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -4520,8 +4520,6 @@ void ReportTable(
print_stack_union(out,lemp,&lineno);
if( lemp->stacksize ){
fprintf(out,"const YYSTACKDEPTH: usize = %s;\n",lemp->stacksize); lineno++;
}else{
fprintf(out,"const YYSTACKDEPTH: usize = 128;\n"); lineno++;
}
if( lemp->errsym && lemp->errsym->useCnt ){
fprintf(out,"const YYERRORSYMBOL: YYCODETYPE = %d;\n",lemp->errsym->index); lineno++;
Expand Down
63 changes: 4 additions & 59 deletions third_party/lemon/lempar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,6 @@ pub struct yyStackEntry {
** is the value of the token */
}

use smallvec::SmallVec;

/* The state of the parser is completely contained in an instance of
** the following structure */
#[allow(non_camel_case_types)]
Expand All @@ -186,7 +184,7 @@ pub struct yyParser<'input> {
//#[cfg(not(feature = "YYNOERRORRECOVERY"))]
yyerrcnt: i32, /* Shifts left before out of the error */
%% /* A place to hold %extra_context */
yystack: SmallVec<[yyStackEntry; YYSTACKDEPTH]>, /* The parser's stack */
yystack: Vec<yyStackEntry>, /* The parser's stack */
}

use std::cmp::Ordering;
Expand Down Expand Up @@ -265,22 +263,9 @@ static yyRuleName: [&str; YYNRULE] = [
*/
impl yyParser<'_> {
fn yy_grow_stack_if_needed(&mut self) -> bool {
if self.yyidx >= self.yystack.capacity() {
if self.yyGrowStack() {
self.yyidx = self.yyidx.checked_sub(1).unwrap();
self.yyStackOverflow();
return true;
}
}
false
}
fn yy_grow_stack_for_push(&mut self) -> bool {
if self.yyidx >= self.yystack.capacity() - 1 {
if self.yyGrowStack() {
self.yyStackOverflow();
return true;
}
}
// yystack is not prefilled with zero value like in C.
if self.yyidx == self.yystack.len() {
self.yystack.push(yyStackEntry::default());
Expand All @@ -289,29 +274,6 @@ impl yyParser<'_> {
}
false
}

#[allow(non_snake_case)]
#[cfg(feature = "YYSTACKDYNAMIC")]
fn yyGrowStack(&mut self) -> bool {
let capacity = self.yystack.capacity();
let additional = capacity + 100;
self.yystack.reserve(additional);
#[cfg(not(feature = "NDEBUG"))]
{
debug!(
target: TARGET,
"Stack grows from {} to {} entries.",
capacity,
self.yystack.capacity()
);
}
false
}
#[allow(non_snake_case)]
#[cfg(not(feature = "YYSTACKDYNAMIC"))]
fn yyGrowStack(&mut self) -> bool {
true
}
}

/* Initialize a new parser.
Expand All @@ -324,7 +286,7 @@ impl yyParser<'_> {
yyidx: 0,
#[cfg(feature = "YYTRACKMAXSTACKDEPTH")]
yyhwm: 0,
yystack: SmallVec::new(),
yystack: Vec::new(),
//#[cfg(not(feature = "YYNOERRORRECOVERY"))]
yyerrcnt: -1,
%% /* Optional %extra_context store */
Expand Down Expand Up @@ -517,26 +479,9 @@ fn yy_find_reduce_action(
yy_action[i as usize]
}

/*
** The following routine is called if the stack overflows.
*/
impl yyParser<'_> {
#[allow(non_snake_case)]
fn yyStackOverflow(&mut self) {
#[cfg(not(feature = "NDEBUG"))]
{
error!(target: TARGET, "Stack Overflow!");
}
while self.yyidx > 0 {
self.yy_pop_parser_stack();
}
/* Here code is inserted which will execute if the parser
** stack every overflows */
/******** Begin %stack_overflow code ******************************************/
/******** Begin %stack_overflow code ******************************************
%%
/******** End %stack_overflow code ********************************************/
}
}
******** End %stack_overflow code ********************************************/

/*
** Print tracing information for a SHIFT action
Expand Down

0 comments on commit 5bf0aa7

Please sign in to comment.