meta icon indicating copy to clipboard operation
meta copied to clipboard

Idea for optimization

Open bvssvni opened this issue 8 years ago • 1 comments

Currently, when a rule matches on a string, it allocates memory. In many formats the parent rule might fail and drop the allocated string.

An idea to optimize this is to push conversion operations instead of meta data, and then convert to meta data at the end of parsing.

bvssvni avatar Jan 06 '17 01:01 bvssvni

Tried the following structure:

/// Represents meta data.
#[derive(PartialEq, Clone, Debug)]
pub enum FastMetaData {
    /// Starts node.
    StartNode(Arc<String>),
    /// Ends node.
    EndNode(Arc<String>),
    /// Sets bool property.
    Bool(Arc<String>, bool),
    /// Sets f64 property.
    F64(Arc<String>, NumberSettings, DebugId),
    /// Sets string property.
    String(Arc<String>, StringFormat, DebugId),
}

There is no point in using slices, because meta data are wrapped in Range<MetaData>. Arc<String> is cloned from meta rules.

This design seems to be a bit worse than the current one:

Before:
test tests::bench_deep_string ... bench:   3,667,948 ns/iter (+/- 1,281,565)
test tests::bench_hello       ... bench:      54,625 ns/iter (+/- 25,679)

After:
test tests::bench_deep_string ... bench:   3,735,350 ns/iter (+/- 478,368)
test tests::bench_hello       ... bench:      58,666 ns/iter (+/- 13,847)

bvssvni avatar Jan 11 '17 14:01 bvssvni