Skip to content

Commit

Permalink
Rework ASCII STL parser and optimize binary STL parser
Browse files Browse the repository at this point in the history
On x86_64 Linux:

```
Benchmarking mesh_loader_parse_binary/from_slice: Collecting 100 samples in estimated 5.0471 s (
mesh_loader_parse_binary/from_slice
                        time:   [15.819 µs 15.835 µs 15.854 µs]
                        thrpt:  [10.867 GiB/s 10.880 GiB/s 10.891 GiB/s]
                 change:
                        time:   [-41.367% -41.236% -41.098%] (p = 0.00 < 0.05)
                        thrpt:  [+69.773% +70.173% +70.551%]
                        Performance has improved.
Found 6 outliers among 100 measurements (6.00%)
  1 (1.00%) low mild
  5 (5.00%) high severe

Benchmarking mesh_loader_parse_binary_large/from_slice: Collecting 15 samples in estimated 5.481
mesh_loader_parse_binary_large/from_slice
                        time:   [11.449 ms 11.463 ms 11.485 ms]
                        thrpt:  [2.4195 GiB/s 2.4241 GiB/s 2.4272 GiB/s]
                 change:
                        time:   [-20.720% -18.883% -17.063%] (p = 0.00 < 0.05)
                        thrpt:  [+20.573% +23.279% +26.135%]
                        Performance has improved.
Found 2 outliers among 15 measurements (13.33%)
  1 (6.67%) high mild
  1 (6.67%) high severe

Benchmarking mesh_loader_parse_binary_very_large/from_slice: Collecting 10 samples in estimated
mesh_loader_parse_binary_very_large/from_slice
                        time:   [42.821 ms 42.892 ms 42.989 ms]
                        thrpt:  [2.6390 GiB/s 2.6449 GiB/s 2.6493 GiB/s]
                 change:
                        time:   [-17.625% -17.078% -16.370%] (p = 0.00 < 0.05)
                        thrpt:  [+19.575% +20.595% +21.397%]
                        Performance has improved.
Found 1 outliers among 10 measurements (10.00%)
  1 (10.00%) high severe

Benchmarking mesh_loader_parse_ascii/from_slice: Collecting 100 samples in estimated 5.2683 s (2
mesh_loader_parse_ascii/from_slice
                        time:   [205.72 µs 205.92 µs 206.14 µs]
                        thrpt:  [1.2716 GiB/s 1.2730 GiB/s 1.2742 GiB/s]
                 change:
                        time:   [-41.095% -40.989% -40.872%] (p = 0.00 < 0.05)
                        thrpt:  [+69.125% +69.460% +69.763%]
                        Performance has improved.
Found 5 outliers among 100 measurements (5.00%)
  4 (4.00%) high mild
  1 (1.00%) high severe

Benchmarking mesh_loader_parse_ascii_large/from_slice: Collecting 100 samples in estimated 5.999
mesh_loader_parse_ascii_large/from_slice
                        time:   [584.37 µs 585.00 µs 585.73 µs]
                        thrpt:  [1.1133 GiB/s 1.1147 GiB/s 1.1159 GiB/s]
                 change:
                        time:   [-43.167% -43.049% -42.931%] (p = 0.00 < 0.05)
                        thrpt:  [+75.227% +75.590% +75.953%]
                        Performance has improved.
Found 6 outliers among 100 measurements (6.00%)
  6 (6.00%) high mild
```

On AArch64 macOS:

```
mesh_loader_parse_binary/from_slice
                        time:   [15.133 µs 15.228 µs 15.328 µs]
                        thrpt:  [11.240 GiB/s 11.313 GiB/s 11.384 GiB/s]
                 change:
                        time:   [-40.453% -40.182% -39.892%] (p = 0.00 < 0.05)
                        thrpt:  [+66.366% +67.173% +67.935%]
                        Performance has improved.

Benchmarking mesh_loader_parse_binary_large/from_slice: Collecting 15 samples in
mesh_loader_parse_binary_large/from_slice
                        time:   [3.9427 ms 3.9728 ms 4.0072 ms]
                        thrpt:  [6.9345 GiB/s 6.9945 GiB/s 7.0479 GiB/s]
                 change:
                        time:   [-37.507% -36.348% -35.035%] (p = 0.00 < 0.05)
                        thrpt:  [+53.930% +57.105% +60.018%]
                        Performance has improved.
Found 1 outliers among 15 measurements (6.67%)
  1 (6.67%) high mild

Benchmarking mesh_loader_parse_binary_very_large/from_slice: Warming up for 3.000
Benchmarking mesh_loader_parse_binary_very_large/from_slice: Collecting 10 sample
mesh_loader_parse_binary_very_large/from_slice
                        time:   [21.061 ms 21.142 ms 21.311 ms]
                        thrpt:  [5.3234 GiB/s 5.3659 GiB/s 5.3864 GiB/s]
                 change:
                        time:   [-35.101% -33.847% -32.527%] (p = 0.00 < 0.05)
                        thrpt:  [+48.207% +51.166% +54.087%]
                        Performance has improved.
Found 2 outliers among 10 measurements (20.00%)
  1 (10.00%) high mild
  1 (10.00%) high severe

Benchmarking mesh_loader_parse_ascii/from_slice: Collecting 100 samples in estima
mesh_loader_parse_ascii/from_slice
                        time:   [268.24 µs 269.40 µs 270.72 µs]
                        thrpt:  [991.49 MiB/s 996.35 MiB/s 1000.7 MiB/s]
                 change:
                        time:   [-42.002% -41.806% -41.573%] (p = 0.00 < 0.05)
                        thrpt:  [+71.154% +71.838% +72.419%]
                        Performance has improved.
Found 15 outliers among 100 measurements (15.00%)
  1 (1.00%) high mild
  14 (14.00%) high severe

Benchmarking mesh_loader_parse_ascii_large/from_slice: Collecting 100 samples in
mesh_loader_parse_ascii_large/from_slice
                        time:   [794.82 µs 799.34 µs 803.99 µs]
                        thrpt:  [830.56 MiB/s 835.39 MiB/s 840.15 MiB/s]
                 change:
                        time:   [-37.552% -37.109% -36.653%] (p = 0.00 < 0.05)
                        thrpt:  [+57.859% +59.006% +60.134%]
                        Performance has improved.
```
  • Loading branch information
taiki-e committed Jan 15, 2024
1 parent c4013e4 commit aa9e65f
Show file tree
Hide file tree
Showing 4 changed files with 536 additions and 389 deletions.
5 changes: 1 addition & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ default = ["stl", "collada"]

# STL (.stl)
# https://en.wikipedia.org/wiki/STL_(file_format)
stl = ["memchr"]
stl = []
# COLLADA (.dae)
# https://en.wikipedia.org/wiki/COLLADA
collada = ["roxmltree"]
Expand All @@ -27,9 +27,6 @@ collada = ["roxmltree"]
# obj = []

[dependencies]
# Used in STL parsing.
memchr = { version = "2.4", optional = true }

# Used in COLLADA parsing.
roxmltree = { version = "0.19", optional = true }

Expand Down
9 changes: 8 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use std::io;
#[cfg(feature = "stl")]
use std::{fmt, path::Path};

use crate::utils::bytes::{bytecount_naive, memrchr_naive};

macro_rules! format_err {
($msg:expr $(,)?) => {
crate::error::invalid_data($msg)
Expand Down Expand Up @@ -41,7 +43,12 @@ pub(crate) struct Location<'a> {

#[cfg(feature = "stl")]
impl<'a> Location<'a> {
pub(crate) fn new(file: Option<&'a Path>, line: usize, column: usize) -> Self {
#[cold]
#[inline(never)]
pub(crate) fn find(remaining: usize, start: &[u8], file: Option<&'a Path>) -> Self {
let pos = start.len() - remaining;
let line = bytecount_naive(b'\n', &start[..pos]) + 1;
let column = memrchr_naive(b'\n', &start[..pos]).unwrap_or(pos) + 1;
Self {
file: file.filter(|&p| p != Path::new("")),
line,
Expand Down
Loading

0 comments on commit aa9e65f

Please sign in to comment.