Fast F#: Read-Only Struct Wrappers

Поделиться
HTML-код
  • Опубликовано: 16 ноя 2024

Комментарии • 12

  • @tw1s73d
    @tw1s73d Год назад

    Thanks for the video! Keep it up!

  • @alexk6745
    @alexk6745 Год назад

    Great! I wonder if that static struct will be consuming sort of twice memory for taht type from the stack? Am I right? I have a feeling that that static type already uses on a heap pointer to the dictionary and we're adding one more. Am I right or not?

  • @robertlenders8755
    @robertlenders8755 Год назад +2

    Thanks for the great video as always. I'm curious if you've done any work with the MemoryMarshal class and the ability to "project" a Span as arbitrary struct data types?

    • @FastFSharp
      @FastFSharp  Год назад +2

      I have. It's super dangerous and rarely necessary. I'll be going deeper and deeper into the darkness with this series so we'll get there 😊

    • @robertlenders8755
      @robertlenders8755 Год назад

      @@FastFSharp I am already down the rabbit hole working with a complex C ABI with unions and variable-length structures. Looking into this technique as a way to work with stack-allocated bytes or byte arrays for interop with minimal copying.

  • @WerewolfAll
    @WerewolfAll Год назад

    Why not to use :> IReadOnlyDictionary interface implemented by Dictionary?

    • @FastFSharp
      @FastFSharp  Год назад +2

      Performance. There is significant performance degradation when you hide concrete types behind interfaces.

  • @ilyamurashov
    @ilyamurashov Год назад +1

    You could hide _values with EditorBrowsableAttribute

    • @FastFSharp
      @FastFSharp  Год назад

      Oh nice! I didn't know that!

  • @jeremybobbin
    @jeremybobbin Год назад

    Interesting that readOnlyDict is suboptimal, and that inlined-functions are subject to member accessibility. Especially from an almost 20-year-old language. What’s going on here?

    • @FastFSharp
      @FastFSharp  Год назад

      The F# compiler is actually inlining that code but the CLR then tries to compile the IL and it's trying to access a private member, therefore it fails.

  • @bentrasmussen7631
    @bentrasmussen7631 Год назад

    What about [] on the indexed property getter - do you think that would have worse performance than using F# compile-time inlining? I guess the F# inline keyword would guarantee inlining whereas the attribute would make inlining likely but not guarantee it - but guarantee no mutation because the internal state would not need to be made public.