0
votes

I have merged small files into big one. On app first start this file is read and one by one small files are created on file system (Isolated Storage).

When this file contains 44 small files and is ~200kb - algorithm works for 120ms on device. When this file contains 140 even smaller files and is ~400kb - algorithm works for 3000 ms on device.

If i take from both files only 44 files - first one still works for ~120, second works for ~800ms.

This seems as wonder for me. Format of data in file is simple

-INT32 - ENTRIES COUNT
--STRING ENTRY NAME         |
--INT32 ENTRY DATA LENGTH   |  REPEATS {ENTRY COUNT} TIMES
--BYTE[] ENTRY DATA         |

For me this seems like a magic in Windows Phone IsolatedStorage mechanisms. There are completely no reasons for second file to work 7-8 times slower when copying equal number of entries.

Repro project - https://www.dropbox.com/s/6bjsve7p8wew3kb/IsoStorageWonder.zip?m

Code:

 public static void CopyCache(ILogger logger)
    {
        using (var isoStorage = IsolatedStorageFile.GetUserStoreForApplication())
        {
            var streamInfo = Application.GetResourceStream(new Uri(_dataFilePath, UriKind.RelativeOrAbsolute));

            isoStorage.CreateDirectory("HttpCache");

            var binaryReader = new BinaryReader(streamInfo.Stream);
            {
                int itemsCount = binaryReader.ReadInt32();

                for (int i = 0; i < ENTRIES_COUNT; i++)
                {
                    string fileName = binaryReader.ReadString();
                    int length = binaryReader.ReadInt32();
                    byte[] data = binaryReader.ReadBytes(length);

                    using (
                        var fileStream =
                            new IsolatedStorageFileStream(
                                Path.Combine(_rootCacheDir, fileName),
                                FileMode.Create,
                                FileAccess.Write,
                                FileShare.None,
                                isoStorage))
                    {
                        fileStream.Write(data, 0, data.Length);
                    }
                }
            }
        }
    }

MAGIC!

1
I am not sure how you test these, but I am getting a consistent 17ms (+/- 2ms) reading from both files.Den Delimarsky
Den, i think u're testing it wrong. Not enumlator, not WP8 should be used, but WP7. As i said i see 120ms on lumia 800. I wonder how did u get 17.Grigory
Grigory, I posted my answer, and I Also from Minsk)). Offtop, sorry.jimpanzer

1 Answers

1
votes

I have similar problem with WebClient performance.
In emulator request takes 0.3-0.5 seconds, on device 8-22 seconds.
I was very confused.
But in my case the solution was very simple: DO NOT TEST PERFORMANCE ON DEVISE IN DEBUG MODE.

What I do:

  1. Compile project to your device.
  2. Stop Debugging
  3. Close your app on phone (and better reboot device)
  4. All works like a charm))

In your test app IsoStorageWonder:

  1. Emulator 551ms
  2. Emulator 256 mB 564ms
  3. HTC Radar WP7.8 Debug Mode 1835ms
  4. HTC Radar WP7.8 Not Debug Mode 958ms

I hope my reserch help you.
Regards

UPD

Test with output2

  1. Emulator 440ms
  2. Emulator 256 mB 447ms
  3. HTC Radar WP7.8 Debug Mode 287ms // very nice
  4. HTC Radar WP7.8 Not Debug Mode 144ms // also nice