Jump to content

Erik@Grijjy

Members
  • Content Count

    36
  • Joined

  • Last visited

  • Days Won

    10

Posts posted by Erik@Grijjy


  1. Delphi 10.4 is just around the corner and you have already been reading about its exciting new language and IDE features. But what has been getting less attention - and what I find equally exciting - is the addition of Metal support for macOS and iOS. See why this can be important for you too as well...

     

    MetalDelphi104.thumb.png.2459dc418fdf6f213384c73aa835bbc5.png

     

    https://blog.grijjy.com/2020/05/25/boost-mac-performance-with-metal-and-delphi-10-4/

    • Like 4
    • Thanks 2

  2. Are you using 3rd party C libraries in your Mac app? Or maybe some custom assembly code? Then things will be different when you switch to 64-bit macOS.

    Maybe this post will give you a head start. It shows how you can use static libraries now, and how you can use an external assembler for your assembly code.

     

    macos64linking.thumb.png.ab12089f39b7f958dafcc01f475262a7.png


    https://blog.grijjy.com/2019/07/19/using-static-libraries-and-assembly-with-64-bit-macos/

    • Thanks 1

  3. 3 minutes ago, Rollo62 said:

    Thanks for the nice library.
    Maybe this is also an useful info to get a better understanding how it is related to the JSON format.

    That definitely makes it easier to work with YAML if you are familiar with JSON. YAML 1.2 is even a superset of JSON, so it can parse JSON as well. Unfortunately (or maybe for the better), libyaml only supports YAML 1.1.


  4. 1 minute ago, David Heffernan said:

    In my codebase at work we use an in-house bespoke wrapper of libyaml.  The big difference from yours, I suspect, is that we needed to support very large files, and opted for a SAX type interface.

    Yes, my library isn't really suitable for very large files, since it loads the entire file into memory. Since YAML is used a lot for small(ish) files, I wanted to keep it simple.

    I may add a SAX type interface at some point. Libyaml already provides a such an interface (it is what I used to build the DOM) and it could be adopted to something more Delphi-friendly...

    • Like 2

  5. 58 minutes ago, Stefan Glienke said:

    Any pure speed benchmark would be rather useless/biased because it all depends on what you are in fact doing apart from creating the list.

    You are mostly right about this. If you have a small list size, you are mostly measuring creation/destruction time. But that is exactly one of the reasons you may want to use a stack-based list instead.

    Although my main motivation wasn't about speed (it was more about memory fragmentation, which is hard to test as you mentioned), I added some speed tests to the repo anyway.

     

    Like you said, any speed test in this area is biased, and does not represent a real-life situation, so you should take the results with a grain of salt. I tested 4 stack list implementations against Delphi's TList<Integer>:

    1. TStackList1 is the original stack list from example 2 (with a fixed configurable size, but doesn't allow managed types).
    2. TStackList2: as TStackList1 but takes Stefan's "put exception at the bottom" suggestion into account.
    3. TStackList3: as TStackList2 but uses inlining
    4. TStackList4: as TStackList1 but uses inlining

    I tested these lists with a buffer of 256 bytes on Win32 using Delphi Rio. This shows how much faster each list is compared to Delphi's TList<Integer>.

    1. TStackList1: 2.78 times faster
    2. TStackList2: 2.77 times faster
    3. TStackList3: 2.81 times faster
    4. TStackList4: 3.03 times faster

    Note that measurements vary a bit from session to session. Sometimes, "putting the exception at the bottom" has a positive impact, sometimes it doesn't. TStackList4 is always the fastest on Win32 though, but the differences aren't that big. On Win64, the results are about the same, but Delphi's TList<Integer> seems to perform a little bit better than on Win32.

     

    Also, as you said, performance depends a lot on the list size. For a list size of 32 bytes, the stack lists are about 10x faster, but for a list size of 2048 bytes, they are only about 1.7x faster. This reinforces my suggestion that stack lists are most suitable for smaller temporary lists. For larger lists, just stick to heap-based collections instead. And you can tweak the capacity as you mentioned to avoid re-allocations.

     

    You can't really test heap usage and fragmentation with these tests. Because we are creating and destroying lists in a loop, a smart memory manager just reuses the same heap memory over and over again without fragmentation. In real-life however, there will be lots of other things going on between the recreation of lists, and fragmentation will be more likely.

    • Like 2

  6. You mean by moving those checks to a separate method? I noticed that method calls are pretty expensive on ARM devices, so I don’t know if it would increase performance in that case. Worth some testing...

     

    We could also assume that the programmer knows what (s)he is doing and remove the check or replace it with an assertion if speed is really that important...


  7. You are right, it is only heap-allocation free. I think I clarified that in the post.

     

    And as I said at the end, "use if appropriate, not just because you can". So if you are running on 32-bit in IIS, then don't use it with large buffers. Small stack-based collections (256 bytes up to 1KB) can still be useful in those situations though...

×