Improve Performance of the Type System (#824)

* export the checker and ensure no methods or fields are exported

* make Checker reusable

* add PatchAndCheck method to Checker, and reuse it in visitors

* avoid unnecessary map and consolidate structs

* make all Nature methods use pointer-receiver

* added cache for type and nature information

* optimize type and nature checks

* more aggressively cache some partial results and add cheap checks

* cache reused values

* reduce copying in Nature by breaking down optional fields

* enforce use of cache

* improve ergonomics of FromType and NatureOf

* improve struct method fetching

* make cache private to Nature

* first iteration improving struct reflect caching

* cleaned up struct fields data

* improve caching of functions data

* simplify checker code

* simplify and remove dead code

* add checker benchmarks

* address PR comments and minor improvements

* rename from SetCache to Bind

* make the benchmarks more fair

* fix benchmark option not being applied

* move Cache to be argument instead of field

* merge FuncData into Optional

* rename Optional to TypeData

* simplify struct logic

* cache builtin numeric types

---------

Co-authored-by: Anton Medvedev <[email protected]>
This commit is contained in:
Diego Augusto Molina
2025-09-18 14:38:27 +02:00
committed by GitHub
co-authored by Anton Medvedev
parent fd562c5c2a
commit a60d994e25
18 changed files with 1389 additions and 955 deletions
+2 -3
View File
@@ -12,7 +12,6 @@ import (
"github.com/expr-lang/expr/builtin"
"github.com/expr-lang/expr/conf"
"github.com/expr-lang/expr/file"
"github.com/expr-lang/expr/parser/lexer"
. "github.com/expr-lang/expr/parser/lexer"
"github.com/expr-lang/expr/parser/operator"
"github.com/expr-lang/expr/parser/utils"
@@ -49,7 +48,7 @@ var predicates = map[string]struct {
// Parser is a reusable parser. The zero value is ready for use.
type Parser struct {
lexer *lexer.Lexer
lexer *Lexer
current, stashed Token
hasStash bool
err *file.Error
@@ -60,7 +59,7 @@ type Parser struct {
func (p *Parser) Parse(input string, config *conf.Config) (*Tree, error) {
if p.lexer == nil {
p.lexer = lexer.New()
p.lexer = New()
}
p.config = config
source := file.NewSource(input)