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 easilly be bypassed either only in release builds :

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
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:

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
// In the application
module AppArgs =
    let parser = ArgumentParser.Create<Arguments>(checkStructure = false)

// In tests
[<Fact>]
let ``Argument structure is correct`` () =
    ArgumentParser<Arguments>.CheckStructure()
union case Arguments.Argument: Arguments
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
  member TypeId : obj
  static member GetCustomAttribute : element:MemberInfo * attributeType:Type -> Attribute + 7 overloads
  static member GetCustomAttributes : element:MemberInfo -> Attribute[] + 15 overloads
  static member IsDefined : element:MemberInfo * attributeType:Type -> bool + 7 overloads

--------------------
System.Attribute() : System.Attribute
val checkStructure : bool
val parser : obj
type Arguments =
  | Argument
    interface obj
    override Usage : string
val ( Argument structure is correct ) : unit -> 'a
Fork me on GitHub