diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2021-07-13 11:41:02 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2021-07-15 17:14:26 +0200 |
commit | 022c4795510306e08a4aba31504ca382d41c7fac (patch) | |
tree | d4c29f62038d0f336d90f32f46bc5b4f5c3ddc28 /hugolib/content_map.go | |
parent | f27e542442d19436f1428cc22bb03aca398d37a7 (diff) |
hugofs: Make FileMeta a struct
This commit started out investigating a `concurrent map read write` issue, ending by replacing the map with a struct.
This is easier to reason about, and it's more effective:
```
name old time/op new time/op delta
SiteNew/Regular_Deep_content_tree-16 71.5ms ± 3% 69.4ms ± 5% ~ (p=0.200 n=4+4)
name old alloc/op new alloc/op delta
SiteNew/Regular_Deep_content_tree-16 29.7MB ± 0% 27.9MB ± 0% -5.82% (p=0.029 n=4+4)
name old allocs/op new allocs/op delta
SiteNew/Regular_Deep_content_tree-16 313k ± 0% 303k ± 0% -3.35% (p=0.029 n=4+4)
```
See #8749
Diffstat (limited to 'hugolib/content_map.go')
-rw-r--r-- | hugolib/content_map.go | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/hugolib/content_map.go b/hugolib/content_map.go index 3f5ed65c3..29e821f75 100644 --- a/hugolib/content_map.go +++ b/hugolib/content_map.go @@ -101,9 +101,9 @@ func newContentMap(cfg contentMapConfig) *contentMap { n := v.(*contentNode) if n.p != nil && !n.p.File().IsZero() { meta := n.p.File().FileInfo().Meta() - if meta.Path() != meta.PathFile() { + if meta.Path != meta.PathFile() { // Keep track of the original mount source. - mountKey := filepath.ToSlash(filepath.Join(meta.Module(), meta.PathFile())) + mountKey := filepath.ToSlash(filepath.Join(meta.Module, meta.PathFile())) addToReverseMap(mountKey, n, m) } } @@ -198,9 +198,9 @@ func (b *cmInsertKeyBuilder) WithFile(fi hugofs.FileMetaInfo) *cmInsertKeyBuilde b.newTopLevel() m := b.m meta := fi.Meta() - p := cleanTreeKey(meta.Path()) + p := cleanTreeKey(meta.Path) bundlePath := m.getBundleDir(meta) - isBundle := meta.Classifier().IsBundle() + isBundle := meta.Classifier.IsBundle() if isBundle { panic("not implemented") } @@ -211,7 +211,7 @@ func (b *cmInsertKeyBuilder) WithFile(fi hugofs.FileMetaInfo) *cmInsertKeyBuilde return b } - id := k + m.reduceKeyPart(p, fi.Meta().Path()) + id := k + m.reduceKeyPart(p, fi.Meta().Path) b.tree = b.m.resources b.key = id b.baseKey = p @@ -347,7 +347,7 @@ func (m *contentMap) AddFiles(fis ...hugofs.FileMetaInfo) error { func (m *contentMap) AddFilesBundle(header hugofs.FileMetaInfo, resources ...hugofs.FileMetaInfo) error { var ( meta = header.Meta() - classifier = meta.Classifier() + classifier = meta.Classifier isBranch = classifier == files.ContentClassBranch bundlePath = m.getBundleDir(meta) @@ -387,7 +387,7 @@ func (m *contentMap) AddFilesBundle(header hugofs.FileMetaInfo, resources ...hug } for _, r := range resources { - rb := b.ForResource(cleanTreeKey(r.Meta().Path())) + rb := b.ForResource(cleanTreeKey(r.Meta().Path)) rb.Insert(&contentNode{fi: r}) } @@ -462,12 +462,12 @@ func (m *contentMap) CreateMissingNodes() error { return nil } -func (m *contentMap) getBundleDir(meta hugofs.FileMeta) string { - dir := cleanTreeKey(filepath.Dir(meta.Path())) +func (m *contentMap) getBundleDir(meta *hugofs.FileMeta) string { + dir := cleanTreeKey(filepath.Dir(meta.Path)) - switch meta.Classifier() { + switch meta.Classifier { case files.ContentClassContent: - return path.Join(dir, meta.TranslationBaseName()) + return path.Join(dir, meta.TranslationBaseName) default: return dir } @@ -476,7 +476,7 @@ func (m *contentMap) getBundleDir(meta hugofs.FileMeta) string { func (m *contentMap) newContentNodeFromFi(fi hugofs.FileMetaInfo) *contentNode { return &contentNode{ fi: fi, - path: strings.TrimPrefix(filepath.ToSlash(fi.Meta().Path()), "/"), + path: strings.TrimPrefix(filepath.ToSlash(fi.Meta().Path), "/"), } } @@ -704,7 +704,7 @@ func (m *contentMap) testDump() string { sb.WriteString("|p:" + c.p.Title()) } if c.fi != nil { - sb.WriteString("|f:" + filepath.ToSlash(c.fi.Meta().Path())) + sb.WriteString("|f:" + filepath.ToSlash(c.fi.Meta().Path)) } return sb.String() } @@ -716,13 +716,13 @@ func (m *contentMap) testDump() string { resourcesPrefix += cmLeafSeparator m.pages.WalkPrefix(s+cmBranchSeparator, func(s string, v interface{}) bool { - sb.WriteString("\t - P: " + filepath.ToSlash((v.(*contentNode).fi.(hugofs.FileMetaInfo)).Meta().Filename()) + "\n") + sb.WriteString("\t - P: " + filepath.ToSlash((v.(*contentNode).fi.(hugofs.FileMetaInfo)).Meta().Filename) + "\n") return false }) } m.resources.WalkPrefix(resourcesPrefix, func(s string, v interface{}) bool { - sb.WriteString("\t - R: " + filepath.ToSlash((v.(*contentNode).fi.(hugofs.FileMetaInfo)).Meta().Filename()) + "\n") + sb.WriteString("\t - R: " + filepath.ToSlash((v.(*contentNode).fi.(hugofs.FileMetaInfo)).Meta().Filename) + "\n") return false }) |