[NOT] Optimizing compiler
-
- Enthusiast
- Posts: 225
- Joined: Sat Jul 07, 2018 6:50 pm
[NOT] Optimizing compiler
Disclaimer: all of the following applies only to development under Windows!
First of all, I would like to say that I think PB is the most pleasant environment (and language) for writing almost any program.
Apart from some special cases for which I use python (mostly tests, not production), or cases when an assembler is needed, this is always true until the performance of the code comes to the fore and there is an unpleasant moment with Pelle C and its bad optimization.
The compiler’s output code performance is noticeably poorer than GCC, Clang, (Intel is good enough, but kind of specific) and sometimes even MSVC (which optimization is second-rate, at least in non latest cl versions).
In some cases (with minor optimizations), you can make edits to the assembler code and good to go.
In some cases, you can write a part of the code in C++, compile with GCC and import it as a static library.
But sometimes, when you need total optimization of the entire code, you have to completely abandon PB and write everything in C\C++ and compiling in GCC.
It is sad.
As far as I understand, there is no possibility to "replace" the compiler (and not only because of the assembler syntax mismatch).
Is it possible to do something else in the field of code optimization?
First of all, I would like to say that I think PB is the most pleasant environment (and language) for writing almost any program.
Apart from some special cases for which I use python (mostly tests, not production), or cases when an assembler is needed, this is always true until the performance of the code comes to the fore and there is an unpleasant moment with Pelle C and its bad optimization.
The compiler’s output code performance is noticeably poorer than GCC, Clang, (Intel is good enough, but kind of specific) and sometimes even MSVC (which optimization is second-rate, at least in non latest cl versions).
In some cases (with minor optimizations), you can make edits to the assembler code and good to go.
In some cases, you can write a part of the code in C++, compile with GCC and import it as a static library.
But sometimes, when you need total optimization of the entire code, you have to completely abandon PB and write everything in C\C++ and compiling in GCC.
It is sad.
As far as I understand, there is no possibility to "replace" the compiler (and not only because of the assembler syntax mismatch).
Is it possible to do something else in the field of code optimization?
Re: [NOT] Optimizing compiler
The compiler allows you to output the asm file that it compiles, allowing you to create your own peephole optimiser to modify the asm before it gets compiledEverything wrote:Is it possible to do something else in the field of code optimization?
Re: [NOT] Optimizing compiler
You get the whole fasm source that is generated and even before that u can use inline assembly.
Some few things might be slower out of the box (and only noticable in edge cases) but usually the community knows what to do.
So even if you dont know fasm u can pretty much always optimize PB code.
Some few things might be slower out of the box (and only noticable in edge cases) but usually the community knows what to do.
So even if you dont know fasm u can pretty much always optimize PB code.
-
- Enthusiast
- Posts: 225
- Joined: Sat Jul 07, 2018 6:50 pm
Re: [NOT] Optimizing compiler
this is exactly what I meant when I wroteKeya wrote:The compiler allows you to output the asm file that it compiles, allowing you to create your own peephole optimiser to modify the asm before it gets compiled
When you need some small optimization it's enough, but when everything need to be optimized it's the same that write app in fasm from scratch which makes using high-level language (PB) meaningless in this case moreover, with a large project, this complicates the development so much that it also makes no sense.In some cases (with minor optimizations), you can make edits to the assembler code and good to go
Modern optimizing compilers are very smart today, even if you consider yourself an assembler guru in most cases they will be able to generate better code!

For example some of gcc options
Re: [NOT] Optimizing compiler
PB in its current form is a rapid prototyping language.
Compiling to ASM instead of C limits the optimization path.
There are hints of LLVM coming and then the playing field will get closer to GCC or CLANG or "insert compiler here".
Compiling to ASM instead of C limits the optimization path.
There are hints of LLVM coming and then the playing field will get closer to GCC or CLANG or "insert compiler here".
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Re: [NOT] Optimizing compiler
Example code please?
Re: [NOT] Optimizing compiler
I also think that it is not a problem of the PB compiler.
Sure, you can speed up everything with asm, but in general PB is very fast.
Most slow stuff is simply not coded in an optimal way.
So yes, a 'slow' example would be nice.
Sure, you can speed up everything with asm, but in general PB is very fast.
Most slow stuff is simply not coded in an optimal way.
So yes, a 'slow' example would be nice.
-
- Enthusiast
- Posts: 225
- Joined: Sat Jul 07, 2018 6:50 pm
Re: [NOT] Optimizing compiler
That would be awesome!There are hints of LLVM coming
There is no 'slow' example

Pelle C output have less performance than OC output (GCC, Clang/LLVM etc) that's fact period

When everything already optimized good compiler is kind of bonus to do a little bit even more.
If people tells you replace your code with asm thats mean:
- The code you are replacing was unusually inefficient. In most cases improving the algorithm is the most rewarding approach.
- Your compiler is generating terrible code
It's all about development cost. Developing in assembler takes much, much more time than in a higher-level language, and reduces readability and maintainability.
Re: [NOT] Optimizing compiler
Crying about edge cases that every language has and ignoring that most of the issues are solvalble even without asm makes no sense to me.Everything wrote:That would be awesome!There are hints of LLVM coming
There is no 'slow' example![]()
Pelle C output have less performance than OC output (GCC, Clang/LLVM etc) that's fact period![]()
When everything already optimized good compiler is kind of bonus to do a little bit even more.
If people tells you replace your code with asm thats mean:Why is that a bad idea?
- The code you are replacing was unusually inefficient. In most cases improving the algorithm is the most rewarding approach.
- Your compiler is generating terrible code
It's all about development cost. Developing in assembler takes much, much more time than in a higher-level language, and reduces readability and maintainability.
The whole point of asm (if available) is to do hands on optimization especially if u want to use specific instructions that might not even be available out of the box.
That PB underperforms in its entirety is nonsense.
Last edited by Mijikai on Wed Mar 10, 2021 7:58 pm, edited 1 time in total.
-
- Enthusiast
- Posts: 225
- Joined: Sat Jul 07, 2018 6:50 pm
Re: [NOT] Optimizing compiler
No one doubts that PB generate perfect code 
Although with default PB (PelleC) optimization enabled, this should not be the case.

Although with default PB (PelleC) optimization enabled, this should not be the case.
Re: [NOT] Optimizing compiler
PureBasic is a one-pass compiler, so there may be one PUSH/POP too many when using constants. Value [ (Push) -> Index <- (POP) ]
I had already written that here.
viewtopic.php?f=35&t=70542#p566769
I had already written that here.
viewtopic.php?f=35&t=70542#p566769
Last edited by mk-soft on Wed Mar 10, 2021 8:58 pm, edited 1 time in total.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: [NOT] Optimizing compiler
My first answer: write better code.Everything wrote:Is it possible to do something else in the field of code optimization?
But ...
If you are so unsatisfied with all available compilers ... write your own.
So you can optimize everything like you want.
But I'm sure there will be other persons who still find your compiler unoptimized.
Or the compilation time will increase a lot, so that they are unsatisfied with the compilation time.
But what exactly is the target of this post

You don't have 'slow' code which someone of us can optimize.
You only tell us the 'code' is not optimized enough.
Are your programs to slow? Are your programs to large?
Your link to 'perfect code' is nonsense.
Yes, there are additional unneeded instructions. (But in my opinion this is not a bug)
But how often are they used in a large loop, so that they really increase the needed time by a high value?
Yes, it would be nice if this can be removed.
But I don't think that any of my many programs will run noticeably faster after that.
Maybe your post would be better placed in feature requests, since only the PB team can optimize the compiler itself.
-
- Enthusiast
- Posts: 225
- Joined: Sat Jul 07, 2018 6:50 pm
Re: [NOT] Optimizing compiler
I agree.infratec wrote:better placed in feature requests
PB is almost perfect and I want to remove the word "almost".
If you are satisfied no matter what, shame on you


Re: [NOT] Optimizing compiler
If you cannot share exact code, what is the general type of program?
Many of us, myself included, started using pb for its native string handling. However, when passing strings as parameters, full copies of the string are made, then the copy is sent. This is horrendously slow, but it's not advertised in documentation. Unfortunately, for "native PB" code to be faster, you still have to revert to those pointers... And the forums are the only place to learn that at this point.
The point is, of you share your code, or at least the struggling section, you'll likely end up with a better, native, solution... Instead of stressing over asm output or imported libraries.
Many of us, myself included, started using pb for its native string handling. However, when passing strings as parameters, full copies of the string are made, then the copy is sent. This is horrendously slow, but it's not advertised in documentation. Unfortunately, for "native PB" code to be faster, you still have to revert to those pointers... And the forums are the only place to learn that at this point.
The point is, of you share your code, or at least the struggling section, you'll likely end up with a better, native, solution... Instead of stressing over asm output or imported libraries.
Re: [NOT] Optimizing compiler
While there could be improvement in the generated assembly it's not usually the cause of poor performance, it's more to do with the code flow not satisfying branch prediction to take advantage of out of order execution or incurring cache hits all the time. If you're careful you can write very fast code with plain PB even string processing can be done very quickly but it's like any language/compiler you have to learn about it's idiosyncrasies and be mindful that you have to also be a master of herding cats as that's pretty much what optimising code is like theses days.Everything wrote:I agree.infratec wrote:better placed in feature requests
PB is almost perfect and I want to remove the word "almost".
If you are satisfied no matter what, shame on you![]()

Here's hoping that PB will evolve
Windows 11, Manjaro, Raspberry Pi OS

