Bug? RandomAccessFile is abnormally slow

Informatix

Expert
Licensed User
Longtime User
I don't know whether it's a bug or something that I missed or don't understand but the RandomAccessFile library is so slow that does not seem normal. In my Cache and Archiver libraries I do many writings to the disk with different kinds of objects and these operations are really fast in comparison.

Look at this (with the same data):
WriteObject with no compression: final size = 1475965 bytes, time needed=3606 ms
WriteObject with compression: final size = 300934 bytes, time needed=13600 ms
WriteObject with encryption: final size = 300949 bytes, time needed=14263 ms

Almost 4 seconds for 1 Mb? Is it normal? To have a comparison basis, I used my Archiver lib to read the file created by WriteObject (with no compression), zip it and save it to the disk with a different name. The whole operation took only 1120 ms !
 

Straker

Active Member
Licensed User
Longtime User
Probably there is something in your code. I've tried that library and my test was very fast. It also depend on the device (of course). Then, are you writing to internal memory or SD card (slower by definition).

May I suggest you to post a piece of code...?
 

Informatix

Expert
Licensed User
Longtime User
It's very basic:
B4X:
        Dim RAF As RandomAccessFile
        RAF.Initialize(File.DirInternal, MyFileName, False)
        RAF.WriteEncryptedObject(MyData, MySecretCode, 0)
        RAF.Close
...and I usually work with many devices at once. The result is the same on all of them (I mean: it's slow on all of them).
It looks like the ouput is not buffered.
 

Straker

Active Member
Licensed User
Longtime User
You are right. I re-checked my test and it used small files.
I tryed to save a list of 100.000 strings of about 12 chars each (1.2MB more or less) and it took 4.7 seconds.
 

MikeS

Member
I am evaluating B4a, and I found the same thing (slow on writing an object). I also got about 4 seconds for a 1Mb file. However I've found that using ReadObject on the same data file is much slower. I get 30 seconds to read in that object and assign it as a Map. I've just come across WriteB4XObject / ReadB4XObject, so I'll try these.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…