TimLariviere / Fabulous-new

Fabulous v2 - Work in progress
https://timothelariviere.com/Fabulous-new/
Other
41 stars 3 forks source link

[Performance] Avoid dynamic dispatch for Convert / ConvertValue in AttributeDefinition #43

Open TimLariviere opened 2 years ago

TimLariviere commented 2 years ago

One thing I was thinking about if we can make convert functions optional (ValueOption). My understanding that it is id function mist of the time. If that is true, skipping calling it with checking for ValueSome is probably worth it in terms of perf.

BUT! it is probably going to be tricky to type properly, given that then we will have to convert 'modelType -> 'valueType.

So maybe a union can be a solution there. just a sketch:

type ScalarAttributeDefinition<'inputType, 'modelType, 'valueType> =
  | NoConverters of .... // 'inputType = 'modelType = 'valueType, are all the same
  | JustModelConverted of ... //  'inputType <> 'modelType ,  'valueType ='modelType
  | JustValueConverter of ... // 'inputType = 'modelType ,  'valueType <> 'modelType
  | ModelAndValueConverters of ... // 'inputType <> 'modelType <> 'valueType, are all different

Feels very clunky but possible worth considering

_Originally posted by @twop in https://github.com/TimLariviere/Fabulous-new/pull/33#discussion_r783669046_