Skip to content

Think about Precompiled templates #27

Description

@ElectricCat10Kv

Consider about Feature to use pre-compiled template to reduce template parsing for higher performance for mass template usage with a bit different values i.e.

type Template struct {
    raw       string
    tokens    []Token  // pre-parsed tokens
}

// Compile parses template single time
func Compile(template string) (*Template, error) {
    tokens, err := parse(template)
    if err != nil {
        return nil, err
    }
    return &Template{raw: template, tokens: tokens}, nil
}

func MustCompile(template string) *Template {
    tmpl, err := Compile(template)
    if err != nil {
        panic(err)
    }
    return tmpl
}

// Methods
func (t *Template) Format(args ...any) string
func (t *Template) FormatComplex(args map[string]any) string

This can be either new methods that uses compilation or toy could modify existing ones

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions