Header menu logo Argu

Performance Tips

Introduction

Argu simplicity is achieved via Reflection and as such it's performance heavily depend on the size and depth of the discriminated union used.

For applications that wants to get a little more performance out of Argu it's also possible to get a little more performance.

Bypassing structure checks

By default Argu checks that the discriminated union is well formed and only contains entries that are valid. This incur both the cost of the checks themselves but also the cost of materializing the whole argument graph that could be loaded only if the corresponding arguments are used.

This check can easily be bypassed either only in release builds :

let checkStructure =
#if DEBUG
    true
#else
    false
#endif

let parser = ArgumentParser.Create<Arguments>(checkStructure = checkStructure)

Or always, forcing the check to happen during unit tests:

// In the application
module AppArgs =
    let parser = ArgumentParser.Create<Arguments>(checkStructure = false)

// In tests
[<Fact>]
let ``Argument structure is correct`` () =
    ArgumentParser<Arguments>.CheckStructure()
namespace Argu
type IArgParserTemplate = abstract Usage: string
<summary> Interface that must be implemented by all Argu template types </summary>
Multiple items
type FactAttribute = inherit Attribute new: unit -> FactAttribute

--------------------
new: unit -> FactAttribute
namespace System
Multiple items
type Attribute = member Equals: obj: obj -> bool member GetHashCode: unit -> int member IsDefaultAttribute: unit -> bool member Match: obj: obj -> bool static member GetCustomAttribute: element: Assembly * attributeType: Type -> Attribute + 7 overloads static member GetCustomAttributes: element: Assembly -> Attribute array + 15 overloads static member IsDefined: element: Assembly * attributeType: Type -> bool + 7 overloads member TypeId: obj
<summary>Represents the base class for custom attributes.</summary>

--------------------
System.Attribute() : System.Attribute
val checkStructure: bool
val parser: ArgumentParser<Arguments>
Multiple items
type ArgumentParser = abstract Accept: visitor: IArgumentParserVisitor<'R> -> 'R member GetArgumentCases: unit -> ArgumentCaseInfo list member GetSubCommandParsers: unit -> ArgumentParser list member PrintCommandLineSyntax: ?programName: string * ?usageStringCharacterWidth: int -> string member PrintUsage: ?message: string * ?programName: string * ?hideSyntax: bool * ?usageStringCharacterWidth: int -> string static member Create: ?programName: string * ?helpTextMessage: string * ?usageStringCharacterWidth: int * ?errorHandler: IExiter * ?checkStructure: bool -> ArgumentParser<#IArgParserTemplate> member ErrorHandler: IExiter member HelpDescription: string member HelpFlags: string list member HelpTextMessage: string option ...
<summary> The Argu type generates an argument parser given a type argument that is an F# discriminated union. It can then be used to parse command line arguments or XML configuration. </summary>

--------------------
type ArgumentParser<'Template (requires 'Template :> IArgParserTemplate)> = inherit ArgumentParser new: ?programName: string * ?helpTextMessage: string * ?usageStringCharacterWidth: int * ?errorHandler: IExiter * ?checkStructure: bool -> ArgumentParser<'Template> override Accept: visitor: IArgumentParserVisitor<'a1> -> 'a1 member GetArgumentCaseInfo: value: 'Template -> ArgumentCaseInfo + 1 overload member GetSubCommandParser: [<ReflectedDefinition>] expr: Expr<(ParseResults<'SubTemplate> -> 'Template)> -> ArgumentParser<'SubTemplate> (requires 'SubTemplate :> IArgParserTemplate) member GetTag: value: 'Template -> int member Parse: ?inputs: string array * ?configurationReader: IConfigurationReader * ?ignoreMissing: bool * ?ignoreUnrecognized: bool * ?raiseOnUsage: bool -> ParseResults<'Template> member ParseCommandLine: ?inputs: string array * ?ignoreMissing: bool * ?ignoreUnrecognized: bool * ?raiseOnUsage: bool -> ParseResults<'Template> member ParseConfiguration: configurationReader: IConfigurationReader * ?ignoreMissing: bool -> ParseResults<'Template> member PrintAppSettingsArguments: args: 'Template list * ?printComments: bool -> string ...
<summary> The Argu type generates an argument parser given a type argument that is an F# discriminated union. It can then be used to parse command line arguments or XML configuration. </summary>

--------------------
new: ?programName: string * ?helpTextMessage: string * ?usageStringCharacterWidth: int * ?errorHandler: IExiter * ?checkStructure: bool -> ArgumentParser<'Template>
static member ArgumentParser.Create: ?programName: string * ?helpTextMessage: string * ?usageStringCharacterWidth: int * ?errorHandler: IExiter * ?checkStructure: bool -> ArgumentParser<#IArgParserTemplate>
type Arguments = | Argument interface IArgParserTemplate

Type something to start searching.