Repository: JetBrains/compose-multiplatform
File: components/resources/library/src/skikoMain/kotlin/org/jetbrains/compose/resources/FontResources.skiko.kt (Kotlin)

Code before:
    val resourceReader = LocalResourceReader.currentOrPreview
    val fontFile by rememberResourceState(resource, weight, style, { defaultEmptyFont }) { env ->
        val path = resource.getResourceItemByEnvironment(env).path
        val key = "$path:$weight:$style"
        fontCache.getOrLoad(key) {
            val fontBytes = resourceReader.read(path)
            Font(path, fontBytes, weight, style)
        }
    }
    return fontFile
}

@Composable
actual fun Font(
    resource: FontResource,
    weight: FontWeight,
    style: FontStyle,
    variationSettings: FontVariation.Settings,
): Font {
    val resourceReader = LocalResourceReader.currentOrPreview
    val fontFile by rememberResourceState(resource, weight, style, variationSettings, { defaultEmptyFont }) { env ->
        val path = resource.getResourceItemByEnvironment(env).path
        val settingsKey = variationSettings.settings
            .sortedBy { it::class.simpleName }
            .joinToString(",") { it::class.simpleName + "_" + it.hashCode() }
        val key = "$path:$weight:$style:$settingsKey"
        fontCache.getOrLoad(key) {
            val fontBytes = resourceReader.read(path)
            Font(key, fontBytes, weight, style, variationSettings)
        }
    }
    return fontFile
}

Review comment (performance):
Looks like this line creates a new ByteArray for every call. The fetch request will resolve from the cache, though. But still the new bytearray would require a new memory allocation (not only on web, but on all platforms).

A potential solution would be to add one more layer of caching - caching for raw bytes. 
But I'm not sure how often it would be needed. It would be very much useful when using the same variable font with many different variationSettings, or just different weight and style. 

 WDYT?



Code after:
actual fun Font(resource: FontResource, weight: FontWeight, style: FontStyle): Font {
    val resourceReader = LocalResourceReader.currentOrPreview
    val fontFile by rememberResourceState(resource, weight, style, { defaultEmptyFont }) { env ->
        val path = resource.getResourceItemByEnvironment(env).path
        val key = "$path:$weight:$style"
        fontCache.getOrLoad(key) {
            val fontBytes = resourceReader.read(path)
            Font(path, fontBytes, weight, style)
        }
    }
    return fontFile
}

@Composable
actual fun Font(
    resource: FontResource,
    weight: FontWeight,
    style: FontStyle,
    variationSettings: FontVariation.Settings,
): Font {
    val resourceReader = LocalResourceReader.currentOrPreview
    val fontFile by rememberResourceState(resource, weight, style, variationSettings, { defaultEmptyFont }) { env ->
        val path = resource.getResourceItemByEnvironment(env).path
        val key = "$path:$weight:$style:${variationSettings.getCacheKey()}"
        fontCache.getOrLoad(key) {
            val fontBytes = resourceReader.read(path)
            Font(key, fontBytes, weight, style, variationSettings)
        }
    }
    return fontFile
}

internal fun FontVariation.Settings.getCacheKey(): String {
    val defaultDensity = Density(1f)
    return settings
        .map { "${it::class.simpleName}(${it.axisName},${it.toVariationValue(defaultDensity)})" }
        .sorted()
        .joinToString(",")
}