I can add some stuff here, because i struggled with similar things.... Some years (2-3) ago i have rewritten the R-bridge (from https://github.com/micclly/mt4R) in free-pascal and used the dll in MT4 very often, i can still remember some details... But don't trust me, try/check it...

1. I would not send that much data over the R-bridge, the good thing is, the bridge does change the transfer mode depending on the type/length of that data (less data = string transfer / more data = chunks or bin files), BUT no matter how, it (the overhead + R's readBin into a matrix) makes it "slow" and you can see (debug only with DebugView.exe) nearly nothing from inside the bridge (just my experience, see TRConsole.AssignVector() / TRConsole.AssignMatrix() in the R-bridge source for details)...

2. Use the R-bridge only for sending short commands, integers, doubles, small strings... Small amounts of data, write all the other stuff in csv files, only send a short command to R to start reading the files. Use data.table fread/fwrite functions, they are pretty fast... And after you now have full control and can see everything, you can choose the path where the files are located... So - if it is not fast enough - use a RAM-DISK to store/transfer files... (normally faster than a SSD)

3. Don't use data-frames in R, they do copy-on-write (modify) that's why they are very slow and inefficient, use data.table. The data.table is (sometimes) harder to use - but - has a lot of advantages and is much faster. It also supports multi-core writing/reading. Use "tracemem" and "microbenchmark" to see what it does, and how fast...

Because of so many problems with speed between Zorro<->R i have now changed the Zorro workflow for my system. I'm now writing my own *.csv files (not via advise(L/S)) for TRAIN and TEST, read them from a RAM-DISK into data.tables in R and use caret (multi-core) to train models on it.

You can also get some more speed by changing how often you create/transfer data. Is it really needed to export the same data again and again? Watch what Zorro normally does...

And!!! Check the R library "memoise", it can cache ANY function call in R + its result (on the RAM-DISK) and store/return that... Even multiple threads can share that! No need to calculate things twice smile




Last edited by laz; 09/05/19 22:10.