Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Better implementation (memory-wise) #1

Open
Labels
@yawnoc

Description

@yawnoc

I don't know very much about programming, so I have produced a rather crappy implementation of the stroke input method.

In particular, I load all the stroke data into memory when the input method service is instantiated:

@Override
publicvoidonCreate()
{
super.onCreate();
loadSequenceCharactersDataIntoMap(SEQUENCE_CHARACTERS_FILE_NAME,charactersFromStrokeDigitSequence);
loadCharactersIntoCodePointSet(CHARACTERS_FILE_NAME_TRADITIONAL,codePointSetTraditional);
loadCharactersIntoCodePointSet(CHARACTERS_FILE_NAME_SIMPLIFIED,codePointSetSimplified);
loadRankingData(RANKING_FILE_NAME_TRADITIONAL,sortingRankFromCodePointTraditional,commonCodePointSetTraditional);
loadRankingData(RANKING_FILE_NAME_SIMPLIFIED,sortingRankFromCodePointSimplified,commonCodePointSetSimplified);
loadPhrasesIntoSet(PHRASES_FILE_NAME_TRADITIONAL,phraseSetTraditional);
loadPhrasesIntoSet(PHRASES_FILE_NAME_SIMPLIFIED,phraseSetSimplified);
updateCandidateOrderPreference();
}

It works, but the downsides are:

  • It takes a long time to load on lower-end devices (e.g. takes 1.2 seconds on my cheap phone with ~1.3 GB RAM)
  • It requires a lot of memory

  1. Most of the time is spent duringloadSequenceCharactersDataIntoMap. Is there a better way of reading a TSV than what I currently have?

    @SuppressWarnings("SameParameterValue")
    privatevoidloadSequenceCharactersDataIntoMap(
    finalStringsequenceCharactersFileName,
    finalMap<String,String>charactersFromStrokeDigitSequence
    )
    {
    finallongstartMilliseconds =System.currentTimeMillis();
    try
    {
    finalInputStreaminputStream =getAssets().open(sequenceCharactersFileName);
    finalBufferedReaderbufferedReader =newBufferedReader(newInputStreamReader(inputStream));
    Stringline;
    while ((line =bufferedReader.readLine()) !=null)
    {
    if (!isCommentLine(line))
    {
    finalString[]sunderedLineArray =Stringy.sunder(line,"\t");
    finalStringstrokeDigitSequence =sunderedLineArray[0];
    finalStringcharacters =sunderedLineArray[1];
    charactersFromStrokeDigitSequence.put(strokeDigitSequence,characters);
    }
    }
    }
    catch (IOExceptionexception)
    {
    exception.printStackTrace();
    }
    finallongendMilliseconds =System.currentTimeMillis();
    sendLoadingTimeLog(sequenceCharactersFileName,startMilliseconds,endMilliseconds);
    }

  2. Alternatively, given that the stroke data is a constant map, is it possible to bake it into the class so that I don't need to load it every time? Or, can we do something completely different that isn't so memory intensive?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp