Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idea for optimization #316

Open
bvssvni opened this issue Jan 6, 2017 · 1 comment
Open

Idea for optimization #316

bvssvni opened this issue Jan 6, 2017 · 1 comment

Comments

@bvssvni
Copy link
Member

bvssvni commented Jan 6, 2017

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
Copy link
Member Author

bvssvni commented Jan 11, 2017

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant