korlibs-archive / korio

Korio: Kotlin cORoutines I/O : Virtual File System + Async/Sync Streams + Async TCP Client/Server + WebSockets for Multiplatform Kotlin 1.3
https://korlibs.soywiz.com/korio/
MIT License
361 stars 34 forks source link

Native: Reading zip file lags the UI. #140

Closed Kesanov closed 2 years ago

Kesanov commented 3 years ago

This code will lag the UI, while reading the content of zip file:

            dir["data.zip"].openUse {
                ZipVfs(this).listRecursiveSimple{ true }.map {
                    val file = dir[it.getPathComponents()]
                    if (it.isDirectory()) file.mkdir() else
                        it.openInputStream().save(file, it.size())
                }
            }
soywiz commented 3 years ago

Can I asume it is related to this? https://github.com/korlibs/korio/issues/138

Kesanov commented 3 years ago

No, I have fixed 138 in my app.

soywiz commented 2 years ago

Used this code for testing:

import com.soywiz.klock.*
import com.soywiz.korge.*
import com.soywiz.korge.tween.*
import com.soywiz.korge.view.*
import com.soywiz.korim.color.*
import com.soywiz.korim.format.*
import com.soywiz.korio.*
import com.soywiz.korio.async.*
import com.soywiz.korio.file.*
import com.soywiz.korio.file.std.*
import com.soywiz.korio.stream.*
import com.soywiz.korma.geom.*
import com.soywiz.korma.interpolation.*

suspend fun main() = Korge(width = 512, height = 512, bgcolor = Colors["#2b2b2b"]) {
    launch {
        val outFolder = localCurrentDirVfs["build/outzip"].apply { mkdirs() }.jail()
        localCurrentDirVfs["bedrock-server-1.17.31.01.zip"].openAsZip { zip ->
            zip.listRecursiveSimple().map {
                val file = outFolder[it.path.trimStart('\\').trimStart('/')]
                val time = measureTime {
                    when {
                        it.isDirectory() -> file.mkdirs()
                        else -> it.copyTo(file)
                    }
                }
                println("$file -> $time")
            }
        }
    }

    val minDegrees = (-16).degrees
    val maxDegrees = (+16).degrees

    val image = image(resourcesVfs["korge.png"].readBitmap()) {
        rotation = maxDegrees
        anchor(.5, .5)
        scale(.8)
        position(256, 256)
    }

    while (true) {
        image.tween(image::rotation[minDegrees], time = 1.seconds, easing = Easing.EASE_IN_OUT)
        image.tween(image::rotation[maxDegrees], time = 1.seconds, easing = Easing.EASE_IN_OUT)
    }
}

Now performance on K/N is much better. Will improve further after this: https://github.com/korlibs/korge/issues/696