Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XML resource optimizations #4559

Merged
merged 16 commits into from
Apr 3, 2024
Merged

XML resource optimizations #4559

merged 16 commits into from
Apr 3, 2024

Conversation

terrakok
Copy link
Collaborator

@terrakok terrakok commented Mar 29, 2024

Users noticed if an app has big a string.xml file it affects the app startup time: #4537

The problem is slow XML parsing.

Possible ways for optimization:

  1. inject text resources direct to the source code
  2. convert XMLs to an optimized format to read it faster

We selected the second way because texts injected to source code have several problems:

  • strict limitations on text size
  • increase compilation and analysation time
  • affects a class loader and GC

Note: android resources do the same and converts xml values to own resources.arsc file

Things was done in the PR:

  1. added support any XML files in the values directory
  2. [BREAKING CHANGE] added Res.array accessor for string-array resources
  3. in a final app there won't be original values*/*.xml files. There will be converted values*/*.cvr files.
  4. generated code points on string resources as file -> offset+size
  5. string resource cache is by item now (it was by the full xml file before)
  6. implemented random access to read CVR files
  7. tasks for syncing ios resources to a final app were seriously refactored to support generated resources (CVR files)
  8. restriction for 3-party resources plugin were deleted
  9. Gradle property compose.resources.always.generate.accessors was deleted. It was for internal needs only.

Fixes #4537

@terrakok terrakok requested a review from pjBooms March 29, 2024 17:39
}
}

override suspend fun readPart(path: String, offset: Long, size: Long): ByteArray {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we read the whole file on web on each string resource? I would cache byte array by path then

.map { it.nodeName to it.attributes.getNamedItem("name").nodeValue }
private fun getValueResourceItems(dataFile: File, qualifiers: List<String>, path: Path) : List<ResourceItem> {
val result = mutableListOf<ResourceItem>()
RandomAccessFile(dataFile, "r").use { f ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simple BufferedReader(FileReader) can be used here as you don't use random access in fact (you could use for file positions instead of calculating offsets manually).

@terrakok terrakok merged commit 5d9dfde into master Apr 3, 2024
3 of 12 checks passed
@terrakok terrakok deleted the k.tskh/str-res-optimization branch April 3, 2024 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

String resources have huge impact on app startup time
2 participants