Jump to content

Arnaud Bouchez

Members
  • Content Count

    316
  • Joined

  • Last visited

  • Days Won

    22

Posts posted by Arnaud Bouchez


  1. Side note: see for instance the ProtectMethod use of https://synopse.info/files/html/Synopse mORMot Framework SAD 1.18.html#TITLE_57 which is similar.

     

    What I miss with records is inheritance.
    Static inheritance, I mean, not virtual inheritance.

    This is why I always like the `object` type, and find it weird that is deprecated and buggy since Delphi 2010...

    Check https://blog.synopse.info/?post/2013/10/09/Good-old-object-is-not-to-be-deprecated-it-is-the-future almost seven years ago... already...

     

    I tend to search for alternatives not in C++, where alternate memory models were added later on - as with Delphi.
    But in new languages like Rust which has a new built-in memory model. Rust memory management is perhaps the most interesting/tricky/difficult/powerful/promising (pickup your own set) feature of this language.

    Both C++ and Delphi suffer from the complexity of all their memory model. COW, TComponent, interface, variant, new/dispose, getmem/freemem, create/free... it may be confusing for newcomers. My guess is that 80% of Delphi RAD users seldom allocate manually memory (just for a few TStringList), and rely on the TComponent ownership and visual design.
    At least they removed ARC from the landscape! 🙂

     

    CMR is a nice addition - which FPC featured since some time, by the way...
    We still need to check the performance impact of this initial release - writing efficient RTL was not the main point of Embarcadero these latest years. I hope it won't reduce regular record/class performance. 

    • Like 2

  2. It is not obvious to me what is the advantage in respect to using an interface-based (or custom variant-base) instance holder.
    You can auto-generate the same try/finally hosting the data within an interface, or a custom variant. Since the oldest Delphi revisions.

    Interfaces can host regular objects with no problem. A custom record may be slightly faster, by allocating its memory on stack and not on heap - but performance is not the main point here, this is about code writability - less source lines, more hidden behavior.

     


  3. 54 minutes ago, David Heffernan said:

    You don't get this because the return type is a managed type and so is actually passed as an extra var parameter.

    Indeed. I would have written an "out" parameter in the docs, at least. The function should set or initialize the value.

    And the compiler should emit a warning in your case.
    FPC is much more paranoid about such warnings, but at least it tries to warn anything dubious, and allow to disable false positives with the {$H-} trick on the faulty line.

    • Like 1

  4. I never install the Delphi 2007 IDE any more. I just copy the dcc.exe and some files (including its dcu) and use the command-line compiler. 
    For testing, it was enough... and nothing to setup, just copy the files from an existing setup.

     

    Edit: But I understand now it won't help you, since I guess you need to validate installation of your IDE plug-in.

    Sorry.


  5. 17 hours ago, Stefan Glienke said:

    However - unless you write core libraries like Arnaud or me you usually don't care.

    This is the main point.

    Premature optimization is the root of all evil! 🙂

     

    @Mahdi Safsafi  Such abstract/broad input about non Delphi compilers has nothing to do with the initial question of this thread, which is performance of string process with Delphi. It is clearly out of scope and subject.
    What does a DSP compiler has in common with the Delphi compiler? Even the MAC units of DSPs have very little in common with regular CPUs.


  6. @Mahdi Safsafi

    My experiment with the Delphi compiler and pointers is not the same as yours. In mORMot, I ended up with using pointers (PUTF8Char=^AnsiChar) for the raw UTF-8 processing, which generated faster code.

    Of course, pointers are difficult to deal with - you need to know what you are doing.

    I always consider pointers by looking at the generated ASM. If the code is better and runs faster with pointer, then I use them. Otherwise I don't.

     

    I am biased for sure: I like pascal because it can be both high-level and modern (like Java/C# - with high-level structures like classes, strings or dynamic arrays), and also system-level (like C). Pointers are clearly for the 2nd level.
    Anyone don't like pointers? Don't use them. But they are pretty convenient and efficient for low-level processing, if the goal is performance.

     

    I like very much when you paternize me with the Gather-scatter pattern. You can perfectly do Gather-scatter with two pointers. This is called pointer arithmetic - which I use extensively in mORMot. So I don't understand what you are talking about.

    • Like 1

  7. 13 hours ago, David Heffernan said:

    It's pretty unlikely to encounter this issue in real code. 

    It occurred to Eric at least with DWS. He actually monitored it before fixing it.
    Of course, he dealt with a language compiler and execution stack, but I guess a lot of other kind of projects may have very tiny objects - if the SOLID principles are properly followed.


  8. 20 hours ago, Mahdi Safsafi said:

    As I mentioned before, Compiler is much able to understand integer behavior over pointer behavior. CPU can also be smart to prefetch next data for you on the background.

    This is not as simple as this. IIRC prefecthing has no difference between indexed (mov ecx, byte ptr [eax+edx]) or direct access (mov ecx, byte ptr[eax]).

    The reference material about instruction latency and execution pipelinging is https://www.agner.org/optimize/instruction_tables.pdf and it is highly depending on the CPU.

    https://www.agner.org/optimize is worth reading and understanding.

     

    https://lemire.me/blog/ is another very interesting blog about performance of text processing, from a lot of experience and actual knowledge.

    Branchless SSE code will be the faster in all circumstances...


    Then use a wall clock measure of full realistic process - not just measuring a loop.

     

    • Like 1

  9. 20 hours ago, Stefan Glienke said:

    @Mahdi Safsafi I just found recently that using a for-to loop with indexing into a pointer was faster than inc(thatpointer).

    It depends on the complexity of the loop.
    For instance, about how variables are assigned to local stack variables or registers. If the use of the for-to index is not mapped into a register, then thatpointer[ i ] will be slower...
    Sometimes, just using a small local functions help the Delphi compiler make better register allocation, and may end up be faster...

     

    Remember 

     🙂

    • Thanks 1

  10. On 7/18/2020 at 3:18 AM, Mahdi Safsafi said:

    Yeah Stefan, I clearly understand you. But the same thing you described can be achieved by branch prediction. So compiler should not generate such code unless you are targeting an old cpu. 

    Branch prediction can do wonders in some micro-benchmarks, but they always have a cost, until the CPU logic actually "warmed up". No branch is always better, since the real problem is branch misprediction.

    Using the asm generated by a recent GCC with tuned optimization flags as a reference is a good hint of what is likely to be more efficient. Intel and AMD are major GCC contributors.
    And a wall clock of a realistic process (not micro benchmark) is the ultimate reference. We use some part of our automated tests as performance benchmark, running some close-to-the reality scenarios.

    • Like 1

  11. On 7/18/2020 at 2:48 AM, Stefan Glienke said:

    The common way of compilers (check it for yourself using compiler explorer) to write while x do is to turn it into if x then repeat until not x (simply said).

    Indeed. This is why I use the "if x then repeat until not x" explicit pattern in time-critical loops of my framework - e.g. when processing JSON.

    As a nice side effect, the variables uses in "x" are more likely to be assigned to registers, since they will be used more often. Sometimes an explicit temporary local variable is needed. Or use of the 'result' variable if it is a PChar.
    Both Delphi and FPC require this, unless "x" is a single simple test, where I have seen FPC able to optimize it IIRC.

    • Like 1

  12. 8 hours ago, David Heffernan said:

    Fossil would be a weird choice. Regardless of how good it is, it's not widespread. git is everywhere, and has so much tooling and resources available. Very hard to see past it. 

    So Delphi would be a weird choice for programming. Regardless of how good it is, it's not widespread any more.

     

    The weirdest David's argument I have never read.
    Alternatives are good. Especially if they are better for simple projects. 😉


  13. For a small and efficient Source Control Management system, even stand-alone with no server, you don't need git, tortoise and whatever...

    Just try https://fossil-scm.org/home/doc/trunk/www/index.wiki

     

    Only a 2MB download, for a full-bloated distributed SCM, with integrated web server, wiki and tickets.

    Perfect for any size of projects.

    It was made by the SQLite3 author, and I use it since years.

     

    Git was meant for Linux. Fossil was made for SQLite3.

    Ensure you read https://fossil-scm.org/home/doc/trunk/www/concepts.wiki
    and https://fossil-scm.org/home/doc/trunk/www/fossil-v-git.wiki

     

    • Thanks 1

  14. At first place, I don't understand how FreeAndNil() on an array pointer could work properly.
    It would try to call a Destroy method in the VMT, which doesn't exist... as @dummzeuch reported above.

     

    What you should do ASAP:

     

    1. Get rid of all those FreeAndNil() on something else than class instances.

     

    2. If you can , try to replace those pointer arrays with dynamic arrays, so you would have reference-counting and automatic free of the content when the variable comes out of scope.
    You can transtype a dynamic array into an array pointer just by using `pointer(aByteDynArray)`.

×