JetBrains / markdown

Markdown parser written in kotlin
Apache License 2.0
682 stars 75 forks source link

Remove fastutil dependency #155

Closed ajalt closed 4 months ago

ajalt commented 5 months ago

As shown in https://github.com/ajalt/clikt/issues/507, the fastutil dependency is over 6MB in size. This dependency is only used in a single line.

This PR removes that dependency and uses the same Stack<Int>() on JVM as on the other platforms.

To make sure this doesn't affect performance, I used the following JMH benchmark that converts the gitBook.md file from the test data to html:

val parser = MarkdownParser(CommonMarkFlavourDescriptor())
val src = Path.of("../src/fileBasedTest/resources/data/html/gitBook.md").readText()

@Warmup(iterations = 5, time = 1)
@Measurement(iterations = 5, time = 1)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@BenchmarkMode(Mode.AverageTime)
@Fork(1)
@State(Scope.Benchmark)
open class GitBookBenchmark {
    @Benchmark
    open fun htmlGenerator(): String {
        val parsedTree = parser.buildMarkdownTreeFromString(src)
        return HtmlGenerator(src, parsedTree, CommonMarkFlavourDescriptor()).generateHtml()
    }
}

Performance on master, with fastutil IntStack:

Benchmark                       Mode  Cnt   Score   Error  Units
GitBookBenchmark.htmlGenerator  avgt    5  19.293 ± 3.356  ms/op

Performance after this PR, with Stack<Int>():

Benchmark                       Mode  Cnt   Score   Error  Units
GitBookBenchmark.htmlGenerator  avgt    5  19.288 ± 7.111  ms/op

According to this benchmark, the change has no performance impact.

KvanTTT commented 5 months ago

Interesting.

As shown in https://github.com/ajalt/clikt/issues/507, the fastutil dependency is over 6MB in size. This dependency is only used in a single line.

Moreover, it isn't compatible with K2 if use KMP, see https://youtrack.jetbrains.com/issue/KT-66723 (but I've written a workaround).

Jerbell commented 4 months ago

Looking forward to this 🤟 (trying to use Clikt in Lambda function)

Jerbell commented 4 months ago

All hail the good folk in the Markdown team. Please consider merging this lovely request & doing a new release 😅