Informatix Expert Licensed User Longtime User Sep 23, 2014 #1 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 !
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 Sep 23, 2014 #2 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...?
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 Sep 23, 2014 #3 It's very basic: Code: Copy 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.
It's very basic: Code: Copy 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 Sep 23, 2014 #4 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.
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.
Erel B4X founder Staff member Licensed User Longtime User Sep 23, 2014 #5 The file size is just one factor. The serialization part (assuming that there is no encryption) is the slowest part.
The file size is just one factor. The serialization part (assuming that there is no encryption) is the slowest part.
MaFu Well-Known Member Licensed User Longtime User Sep 23, 2014 #6 The B4A RandomAccessFile is based on the Java.io.RandomAccessFile class which isn't buffered. Therefore it's slow as hell on larger files.
The B4A RandomAccessFile is based on the Java.io.RandomAccessFile class which isn't buffered. Therefore it's slow as hell on larger files.
Informatix Expert Licensed User Longtime User Sep 24, 2014 #7 I wrote my own library to encrypt and save byte arrays (with compression) and the time to encrypt and write the file of post #1 is now under 40 ms !!!
I wrote my own library to encrypt and save byte arrays (with compression) and the time to encrypt and write the file of post #1 is now under 40 ms !!!
M MikeS Member Jan 6, 2015 #8 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.
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.
Erel B4X founder Staff member Licensed User Longtime User Jan 6, 2015 #9 The B4XObject methods should be much faster. If you like you can upload your project with the file and I'll run a test with these methods instead of WriteObject / ReadObject.
The B4XObject methods should be much faster. If you like you can upload your project with the file and I'll run a test with these methods instead of WriteObject / ReadObject.
M MikeS Member Jan 6, 2015 #10 Thanks Erel - I made another thread about this matter (with sample project) after I realised I couldn't try WriteB4XObject / ReadB4XObject on a trial. Please see the following link. https://www.b4x.com/android/forum/t...oad-a-word-list-into-a-map.49023/#post-304940
Thanks Erel - I made another thread about this matter (with sample project) after I realised I couldn't try WriteB4XObject / ReadB4XObject on a trial. Please see the following link. https://www.b4x.com/android/forum/t...oad-a-word-list-into-a-map.49023/#post-304940