Skip to content

Commit

Permalink
perf(expr): complete expression benchmark framework (#6995)
Browse files Browse the repository at this point in the history
This PR completes the micro-benchmark framework for expressions.

It can be run with:
```sh
cd src/expr
# run all benches
cargo bench --bench expr -- --quick
# list all benches
cargo bench --bench expr -- --list
# run specified benches
cargo bench --bench expr -- --quick "add\(int32,int32\)"
```

The detailed bench results have been updated to #6868.
Here is a statistical overview of all expressions:

<img width="470" alt="截屏2022-12-20 21 13 24" src="https://user-images.githubusercontent.com/15158738/208812177-529f62aa-4590-4dbc-b93b-9d8f1151418c.png">

To enumerate all valid expressions, we utilize the function signature maps defined in the frontend. We moved them into the expr crate in order to avoid dependency on the frontend thus reducing the compilation time.

Approved-By: lmatz
  • Loading branch information
wangrunji0408 authored Dec 23, 2022
1 parent 12bb0cb commit d28768e
Show file tree
Hide file tree
Showing 14 changed files with 977 additions and 587 deletions.
32 changes: 29 additions & 3 deletions src/common/src/array/utf8_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::fmt::{Display, Write};

use risingwave_pb::data::{Array as ProstArray, ArrayType};

use super::bytes_array::{BytesWriter, PartialBytesWriter, WrittenGuard};
Expand Down Expand Up @@ -120,6 +122,25 @@ impl Utf8Array {
.into_single_value()
.map(|bytes| unsafe { std::str::from_boxed_utf8_unchecked(bytes) })
}

pub fn into_bytes_array(self) -> BytesArray {
self.bytes
}

pub fn from_iter_display(iter: impl IntoIterator<Item = Option<impl Display>>) -> Self {
let iter = iter.into_iter();
let mut builder = Utf8ArrayBuilder::new(iter.size_hint().0);
for e in iter {
if let Some(s) = e {
let mut writer = builder.writer().begin();
write!(writer, "{}", s).unwrap();
writer.finish();
} else {
builder.append_null();
}
}
builder.finish()
}
}

/// `Utf8ArrayBuilder` use `&str` to build an `Utf8Array`.
Expand Down Expand Up @@ -184,9 +205,7 @@ impl<'a> StringWriter<'a> {
pub fn write_from_char_iter(self, iter: impl Iterator<Item = char>) -> WrittenGuard {
let mut writer = self.begin();
for c in iter {
let mut buf = [0; 4];
let result = c.encode_utf8(&mut buf);
writer.write_ref(result);
writer.write_char(c).unwrap();
}
writer.finish()
}
Expand Down Expand Up @@ -222,6 +241,13 @@ impl<'a> PartialStringWriter<'a> {
}
}

impl Write for PartialStringWriter<'_> {
fn write_str(&mut self, s: &str) -> std::fmt::Result {
self.write_ref(s);
Ok(())
}
}

#[cfg(test)]
mod tests {
use std::hash::Hash;
Expand Down
10 changes: 10 additions & 0 deletions src/expr/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## Run Microbenchmarks

```sh
# run all benches
cargo bench --bench expr -- --quick
# list all benches
cargo bench --bench expr -- --list
# run specified benches
cargo bench --bench expr -- --quick "add\(int32,int32\)"
```
Loading

0 comments on commit d28768e

Please sign in to comment.