Skip to content

perf: implement request parsing result caching #192

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

mervyn-mccreight
Copy link
Collaborator

@mervyn-mccreight mervyn-mccreight commented Feb 5, 2025

No description provided.

@mervyn-mccreight mervyn-mccreight changed the title feat(execution): introduce request parsing result caching perf: introduce request parsing result caching Feb 5, 2025
@mervyn-mccreight mervyn-mccreight changed the title perf: introduce request parsing result caching perf: implement request parsing result caching Feb 5, 2025
Copy link
Owner

@stuebingerb stuebingerb left a comment

Choose a reason for hiding this comment

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

No real blocker but maybe a few quick wins

fun parseValueLiteral(isConst: Boolean): ValueNode {
val token = lexer.token
internal fun Lexer.parseValueLiteral(isConst: Boolean): ValueNode {
val token = token
Copy link
Owner

Choose a reason for hiding this comment

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

This looks very confusing, maybe you can reword assignments like this.

}

/**
* Converts a name lex token into a name parse node.
*/
private fun parseName(): NameNode {
private fun Lexer.parseName(): NameNode {
Copy link
Owner

Choose a reason for hiding this comment

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

Seeing all these extension functions somehow feels strange (especially since I wouldn't necessarily consider them semantically belonging to a lexer) but I get where this comes from. Not sure if creating a new Parser instance would be so bad but I'm fine either way - haven't looked at the Parser/Lexer too closely so far.

import kotlin.reflect.KClass

class DefaultSchema(
override val configuration: SchemaConfiguration,
internal val model: SchemaModel
) : Schema, __Schema by model, LookupSchema {
) : Schema, __Schema by model, LookupSchema, CoroutineScope {
Copy link
Owner

Choose a reason for hiding this comment

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

Feels a bit strange that a schema also is a coroutine scope but that can either be just me or a bad name for DefaultSchema 😉 (but I wouldn't suggest renaming the class now)

fun `calls function once on multiple invocations with same input`() = runTest {
val memoized = memoize(this, 1, ::slowPlusOne)
repeat(2) { assertEquals(2, memoized(1)) }
assertEquals(slowFunctionDuration.inWholeMilliseconds, testScheduler.currentTime)
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
assertEquals(slowFunctionDuration.inWholeMilliseconds, testScheduler.currentTime)
// Only one delay of [slowFunctionDuration] should have happened, indicating that
// `slowPlusOne` was executed only once
assertEquals(slowFunctionDuration.inWholeMilliseconds, testScheduler.currentTime)

Maybe a comment like that helps for future understanding

@@ -14,7 +14,7 @@ import java.util.concurrent.TimeUnit
@State(Scope.Benchmark)
@Warmup(iterations = 10)
@Measurement(iterations = 5)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@OutputTimeUnit(TimeUnit.SECONDS)
open class RequestCachingBenchmark {
Copy link
Owner

Choose a reason for hiding this comment

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

I know this is old code but it looks like this benchmark is primarily measuring the execution, not the parsing. Can we have a dedicated benchmark for parsing (as well), maybe with different kinds of requests?

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.

2 participants