Comments (2)
Did a quick test.
package main
import (
"crypto/sha256"
"fmt"
"io"
"log"
"os"
"time"
"github.com/a-h/templ/generator"
"github.com/a-h/templ/parser/v2"
)
func main() {
var err error
var now time.Time
now = time.Now()
err = hashPath()
if err != nil {
log.Fatal(err)
}
fmt.Printf("hashPath: ms: %d\n", time.Since(now).Milliseconds())
now = time.Now()
err = generatePath()
if err != nil {
log.Fatal(err)
}
fmt.Printf("generatePath: ms: %d\n", time.Since(now).Milliseconds())
}
func hashPath() (err error) {
f, err := os.Open("template.templ")
if err != nil {
return
}
defer f.Close()
h := sha256.New()
if _, err = io.Copy(h, f); err != nil {
return err
}
fmt.Printf("%x\n", h.Sum(nil))
return err
}
func generatePath() (err error) {
t, err := parser.Parse("template.templ")
if err != nil {
return
}
outputFileName := "template_temp.go"
outputFile, err := os.Create(outputFileName)
if err != nil {
return
}
_, err = generator.Generate(t, outputFile)
return err
}
0 0 /Users/adrian/github.com/a-h/templ/generator/test-complex-attributes % ./hash
0f3bd5fb1a37ce30dce13849dfb40009dda13e742bb10cb394012b73adb4fe9f
hashPath: ms: 0
generatePath: ms: 5
Although there would be a small overhead in maintaining the hash list, it's likely faster overall to skip generating files that haven't changed by recalculating the hash.
But only by around 5ms per file.
from templ.
Fixed in #366
from templ.
Related Issues (20)
- question: Escape go keywords at the beginning of the line HOT 3
- generator: Duplicate Import Statements in Generated Templates Cause go build Failure HOT 5
- vscode: folded files in tree view seem to not work when rust-analyzer is installed HOT 2
- Issue: Unexpected Script Placement in Generated HTML HOT 3
- fmt: <pre> tags not handled correctly HOT 3
- parser: style attribute of DOM element doesn't accept dynamic styles HOT 1
- proposal: Typed Children for Wrappers HOT 2
- Proposal: Allow spreading List of `templ.Components`, similar to `{ children ... }` HOT 1
- css expression: found unexpected parameters HOT 2
- generator: Add nonce support for style tags
- Abandoned change to not modify files where fmt makes no changes HOT 3
- Proposal: Load file as templ HOT 4
- Help with intercepting middleware, and writing responses HOT 4
- Proposal: Change URL's signature to match [S]Printf HOT 3
- Script application/ld+json HOT 4
- lsp error when ı reload or open templ file HOT 8
- [v0.2.717] error: column is beyond end of line HOT 23
- Connection to server got closed. Server will not be restarted. (source: templ-vscode) HOT 4
- proposal: Cache-bust Static Assets HOT 4
- I am getting error with templ-vscode extension HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from templ.