×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    34

    Thumbs up RMS and GetResource -- tooo slow on some devices

    Hi,

    I have MIDP application,We have 2 RMS. when the application is accessed first time, it will check for existing RMS,if no RMS found, it will dump the data from Resource file 1 to RMS1, and Resource file 2 to RMS2.

    i.e. when i download and install the app, First time it will call the code

    something like LoadRMSFromResource(resource,rmsname). For subsequent access of Application, it directly read From RMS and this method will not called.


    jar size - 55k
    resource file1- 55k
    resource file2-75k


    The problem is, when ***some of my users*** downaloding the app and install first time, it takes 5minutes to 9 minutes ! This is tooo much time.

    What we are doing is

    GetResourceAsStream--->InputStream--->InputStreamReader

    InputStreamReaderA.read(buf,0,1024*4) //Previously we were reading one character... then we are reading 1024 character...then 1024*4 character !!! Performance is imporoving... but still it is too much time !!!



    ----
    On Second approach...we tried to remove getResrouceAsStream and we put All data, in separate class file, and it will write to RMS directly. but in that case, Jar file size is increased much (Approx 150k+) !


    Any thoughts, how can we do some optimization ?


    Thanks in Advance
    Raxit Sheth
    Mobile 4 Mumbai
    www.m4mum.com

  2. #2
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,405

    Re: RMS and GetResource -- tooo slow on some devices

    Hi raxitsheth,

    do you know the devices that show this behaviour? Also, is your MIDlet installed on an external memory on these devices?

    About your second approach: does the JAR size increase that much even if you remove the resources from within the JAR itself?

    Pit

  3. #3
    Nokia Developer Expert
    Join Date
    Jun 2005
    Posts
    923

    Re: RMS and GetResource -- tooo slow on some devices

    Post the code being used to read from the file and write to the RMS and read from RMS later on.

    Daniel

  4. #4
    Nokia Developer Expert
    Join Date
    Jun 2005
    Posts
    923

    Re: RMS and GetResource -- tooo slow on some devices

    Also make sure you are not reading all this data from the GUI thread, as this will block all user input.

    Daniel

  5. #5
    Registered User
    Join Date
    Apr 2008
    Posts
    34

    Re: RMS and GetResource -- tooo slow on some devices

    @Jappit,


    Device is mainly N-Series, Till time we face problem Specifically on Nokia N81.


    in our second approach, where completely removing getresourceasstream... and put new class file we forgot to remove the data file from res, but after doing that.


    c.class -- 160k (after obsfucation)
    jar file size is 74k


    Any clue ?

    -Raxit

  6. #6
    Registered User
    Join Date
    Apr 2008
    Posts
    34

    Re: RMS and GetResource -- tooo slow on some devices

    Hi,

    we are using GUI thread only...indeed we want user should not able to put any input.
    Please note, this method will get invoked only once, when user first time access the app after installation...at this time, it will read data from Resource, and write it to RMS.

    For next subsequent access, this method will not call.

    -Raxit

  7. #7
    Registered User
    Join Date
    Apr 2008
    Posts
    34

    Re: RMS and GetResource -- tooo slow on some devices

    /***********************
    opensourced licensce under GPL. -- for commercial use, please contact raxit@m4mum.com

    import standard.disclaimar.*

    All rights reserved Mobile 4 Mumbai, www.m4mum.com, raxit@m4mum.com


    This function read Resource filename, parse a line, and add a record entry to RecStoreName

    Each line of file is mapped with a record store entry

    ********************/



    private void LoadRMSFromFileNew(String filename, String RecStoreName) {

    try {

    InputStream inputStreamTxt_ = this.getClass().getResourceAsStream(filename);
    InputStreamReader inputStreamTxt =new InputStreamReader (inputStreamTxt_);
    RecordStore rs = RecordStore.openRecordStore(RecStoreName, true);



    int i=0;
    char[] buf = new char[10240*4];



    /***************************
    Read 10240*4 = 40k into buffer till end of file.
    Parse Each new line,
    add new line to record store.
    Remaining data, will be used in next iteration of loop
    ****************************/

    int lastindex=0,index=0;
    StringBuffer remaining = new StringBuffer("");
    String line= null;

    while(inputStreamTxt.read(buf,0,10240*4)>-1)
    {
    i++;

    remaining.append(buf);

    lastindex=0;index=-1; //(re)set the index.


    while((index=remaining.toString().indexOf("\n", lastindex))!=-1)
    {


    line = new String (remaining.toString().substring(lastindex, index));
    writeRecord(line, rs);// This will Write line to rs.
    lastindex=index+1;
    }

    remaining=new StringBuffer(remaining.toString().substring(lastindex));

    buf = new char[10240*4]; // Java does not have memset like C !

    }


    buf=new char [1]; // This is unnecessary !

    closeRecStore(rs);
    }catch(Exception e){}
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •