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

Feature request: Ineffective .with_regex(false) when parsing in EnvFilter::builder in build #2702

Closed
SajjadPourali opened this issue Aug 29, 2023 · 2 comments

Comments

@SajjadPourali
Copy link

SajjadPourali commented Aug 29, 2023

pub(super) fn parse(from: &str, regex: bool) -> Result<Self, ParseError> {

The parse method internally calls all the methods of EnvFilter::builder, and since it checks the regex during runtime, its dependency will remain in the code.

    let cmd = EnvFilter::builder()
        .with_regex(false)
        .with_default_directive(LevelFilter::INFO.into())
        .parse(var)
        .unwrap();
 File  .text     Size Crate
 7.5%  25.1% 326.6KiB std
 4.1%  13.7% 177.5KiB regex_automata
 2.9%   9.7% 125.4KiB [Unknown]
 2.3%   7.7%  99.9KiB regex_syntax
 1.6%   5.3%  68.3KiB ...
....
tracing-subscriber = "0.3.17"

It would be really nice to have a feature to disable it during code compilation to reduce the binary size.

@SajjadPourali SajjadPourali changed the title Ineffective .with_regex(false) when parsing in EnvFilter::builder Ineffective .with_regex(false) when parsing in EnvFilter::builder Aug 29, 2023
@SajjadPourali SajjadPourali changed the title Ineffective .with_regex(false) when parsing in EnvFilter::builder Feture request .with_regex(false) when parsing in EnvFilter::builder in build Aug 29, 2023
@SajjadPourali SajjadPourali changed the title Feture request .with_regex(false) when parsing in EnvFilter::builder in build Feture request: Ineffective .with_regex(false) when parsing in EnvFilter::builder in build Aug 29, 2023
@SajjadPourali SajjadPourali changed the title Feture request: Ineffective .with_regex(false) when parsing in EnvFilter::builder in build Feature request: Ineffective .with_regex(false) when parsing in EnvFilter::builder in build Aug 29, 2023
@hawkw
Copy link
Member

hawkw commented Aug 29, 2023

with_regex(false) simply disables the support for matching regular expressions in the filter. However, env_filter also uses regular expressions to parse the filter from an input string, so EnvFilter would not be available at all without a regex dependency.

If you're concerned about the binary size impact of regex, and you're not relying on EnvFilter features like matching on field values, you may want to consider using the Targets filter instead. Targets implements a subset of the filtering syntax supported by EnvFilter: it can match on events and spans based on their target/module path.

Essentially, the Targets filter implements the parts of EnvFilter that can easily be implemented without a dependency on regex. So, in a sense, the feature flag for disabling regex already exists: just disable the env_filter feature and use the Targets filter, instead.

Hope that's helpful!

@SajjadPourali
Copy link
Author

Perfect, that's exactly what I was looking for.

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

No branches or pull requests

2 participants