Is MQL compiled or interpreted? - page 6

 
Anthony Garot:

"Module ex5 contains both versions of the code at once (32 bit and 64 bit)."

That's interesting.

Anyway, let me explain why I feel prior versions were interpreted. Feel free to shoot this with bullets.

1. It just felt that way. Everything was run through the MetaQuotes environment. I've not seen anyone say, "Oh, just change the .ex4 to .exe and run it." MT4 always felt clunky to me, like there were extra layers involved. I realize this is just a gut feeling, but there you have it.

2. Something Enrique pointed out . . . MT4 code was easily decompiled. I may be showing my ignorance, but wouldn't P-code be easier to decompile than a .exe? Yes, I realize they have taken steps to obfuscate (or fuzzification—what a great word!) since the MT4 days. But have you ever seen decompiled MT4 code? It looks like real code with the variable names changed. (For the record, I do not use decompiled code. I am a strong believer in rolling your own.)

3. I once architected a home software package. So what's the first thing you do when you design a software package for a company? Gather requirements.

So, I talked to the CEO, and he wanted it to be cross-platform. Oh hell. So I gave him some options of languages, libraries, etc. that would facilitate this. I tried to make it very clear that this would introduce unknowns and take more development time. That was all OK—he wanted it cross platform. Well, as you can image, the software was released on Windows-only, the Mac port never happened, and all those hours and design tradeoffs were wasted.

Thus, I imagine some sort of early discussions at MetaQuotes of a similar nature. "Oh, sure, we can have it write P-code, have it run through an interpreter, and the .ex4 (.ex3?) files can simply be copied between platforms." In fact, this actually sounds like a really cool thing to write.

Then somewhere around 2015 they realized they hadn't released anything for Mac, they already had a significant part of market-share, customer support was already a pain in the bum, and a user can simply run MetaQuotes products on Wine / Mac OS reasonably well. No reason to keep going with a non-native boondoggle any more.

- -

OK, I realize some of this is stretching a bit.

Native code doesn't mean it should be packed into PE- MZ- or whatsoever public format. They wanted something encrypted and proprietary. Hence this is not a plain executable.

As I posted in the reference above, MT4 was initially a bytecode, but then changed to compiled version in sync with MQL5, to improve code protection.

Your story is correct, but I don't know MQ vision. I only know they constantly do things which I'd never do.

 
Stanislav Korotky:

...In MT4 it was a byte code...

Thank you for those details. For me execution of byte code counts as interpreted, others may see this more strict.

Anthony Garot: ...MT4 code was easily decompiled...

For me this has always been technical prove that MQL4 is not compiled to native code. From machine code a decompiler cannot produce sources the way Pure-Beam did.
 
Stanislav Korotky:

As I posted in the reference above, MT4 was initially a bytecode, but then changed to compiled version in sync with MQL5, to improve code protection.

Oops! I missed that post.

alphatrading:

Thank you for those details. For me execution of byte code counts as interpreted, others may see this more strict.

I see execution of bytecode as "interpreted" also.

 

More on this (essentially the same info from MQ) in russian. That's enough I think ;-).

Angels can be both genders, or neither.

 

From Renat's post:

At the first stage of compilation, universal bytecode is stored, but when executed in the terminal, this byte code is fully 100% translated into native 32 or 64 bit code with additional optimization.


Please correct me if I'm wrong: It means EX4 and EX5 contain protected byte code. Translation to native code happens at runtime, we have something like in Java - a JIT compiler.

edit: After re-reading the last link Stanislav posted. When Renat says "optimization" he means the native compiler. In that post he explicitly says that optimization (native compiler) is not used for MQL4 and MT4 at all. Which exactly matches his former post with the table of speed comparisons.

 

Producing a file, even a bytecode, is called compiling.

At most, what is interpreted is the ex4 after it was created as ex4 and when we ask for it to run. 

This was my first view in this thread. Maybe it was that way in MT4, maybe it still is - though for MT to get the best results they should strive to compile all the way to native from the beginning. And maybe they did it as Stanislav pointed out, which makes sense. In any case, our source code, mql4 or mql5 is compiled, to bytecode or to machine. That is for sure. 

 
My fault guys... I should have been more specific in the OP. I also consider byte-code to be interpreted since it requires an interpreter/RE to run on the machine. 
 

But given that MQL5 new compiler has optimizations of code, means that it most probably compiles to machine code - and not to bytecode.
Because optimization of code is most meaningful for machine code outcome, not for bytecode. 

So, most probably that ex5 is machine code.

 
Thanks to everyone ITT for the enlightening information!
 

Been reading this thread and decided to make a practical approach instead of theoretical ...

For tests I used iDwma (Inverse Distance Weighted Moving Average) since it is, due to the way it is calculated, a good candidate for testing what, more or less, the name of the thread is asking.

The "pure" MQL version used for testing / comparison was the version from here : iDwm - Inverse Distance Weighted Moving Average which is not having any serious MQL issues that should be corrected in order to make it an optimal MQL code (on the contrary - it is even using built in ma to get the prices faster - which I don't use in the attached code). The other version is the one attached at this post : it is basically the same, except C++ dll is used for iDwma calculation.


Results of the profiler tests, on roughly 3.5M historical ticks - the pure MQL version results :


And the results of the attached version :

Results are for 32 bit MT5 (the attached dll is a 32 bit version too). Similar difference is for the 64 bit though. All the data is here - same conditions, same settings - draw your own conclusions

PS: if you attempt to use longer periods for iDwma, be aware that "pure MQL" version can cause you an early lunch while waiting for it to terminate the tests

PPS: the difference in values comes from the only change that needs to be made in the code base example used (it is using "<=" in two occasions when it should be using "<". Set the period in that example to period -1 to have the same results


IDWMA
IDWMA
  • www.mql5.com
Indicator IDWMA (Inverse Distance Weighted Moving Average) is a moving average that is not sensitive to switching the timeframe, but more efficient on the higher timframes of the chart. MA calculation algorithm is that the indicator line...
Files:
idwma_2.mq5  7 kb
iDwma.zip  44 kb