mirror of
https://github.com/tendermint/tendermint.git
synced 2026-08-21 22:56:22 +00:00
Performance improvements for the event query API (#7319)
Rework the implementation of event query parsing and execution to improve performance and reduce memory usage. Previous memory and CPU profiles of the pubsub service showed query processing as a significant hotspot. While we don't have evidence that this is visibly hurting users, fixing it is fairly easy and self-contained. Updates #6439. Typical benchmark results comparing the original implementation (PEG) with the reworked implementation (Custom): ``` TEST TIME/OP BYTES/OP ALLOCS/OP SPEEDUP MEM SAVING BenchmarkParsePEG-12 51716 ns 526832 27 BenchmarkParseCustom-12 2167 ns 4616 17 23.8x 99.1% BenchmarkMatchPEG-12 3086 ns 1097 22 BenchmarkMatchCustom-12 294.2 ns 64 3 10.5x 94.1% ``` Components: * Add a basic parsing benchmark. * Move the original query implementation to a subdirectory. * Add lexical scanner for Query expressions. * Add a parser for Query expressions. * Implement query compiler. * Add test cases based on OpenAPI examples. * Add MustCompile to replace the original MustParse, and update usage.
This commit is contained in:
+2
-2
@@ -232,11 +232,11 @@ var (
|
||||
)
|
||||
|
||||
func EventQueryTxFor(tx Tx) tmpubsub.Query {
|
||||
return tmquery.MustParse(fmt.Sprintf("%s='%s' AND %s='%X'", EventTypeKey, EventTxValue, TxHashKey, tx.Hash()))
|
||||
return tmquery.MustCompile(fmt.Sprintf("%s='%s' AND %s='%X'", EventTypeKey, EventTxValue, TxHashKey, tx.Hash()))
|
||||
}
|
||||
|
||||
func QueryForEvent(eventValue string) tmpubsub.Query {
|
||||
return tmquery.MustParse(fmt.Sprintf("%s='%s'", EventTypeKey, eventValue))
|
||||
return tmquery.MustCompile(fmt.Sprintf("%s='%s'", EventTypeKey, eventValue))
|
||||
}
|
||||
|
||||
// BlockEventPublisher publishes all block related events
|
||||
|
||||
@@ -10,18 +10,18 @@ import (
|
||||
func TestQueryTxFor(t *testing.T) {
|
||||
tx := Tx("foo")
|
||||
assert.Equal(t,
|
||||
fmt.Sprintf("tm.event='Tx' AND tx.hash='%X'", tx.Hash()),
|
||||
fmt.Sprintf("tm.event = 'Tx' AND tx.hash = '%X'", tx.Hash()),
|
||||
EventQueryTxFor(tx).String(),
|
||||
)
|
||||
}
|
||||
|
||||
func TestQueryForEvent(t *testing.T) {
|
||||
assert.Equal(t,
|
||||
"tm.event='NewBlock'",
|
||||
"tm.event = 'NewBlock'",
|
||||
QueryForEvent(EventNewBlockValue).String(),
|
||||
)
|
||||
assert.Equal(t,
|
||||
"tm.event='NewEvidence'",
|
||||
"tm.event = 'NewEvidence'",
|
||||
QueryForEvent(EventNewEvidenceValue).String(),
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user