Replies: 3 comments 5 replies
-
goldmark's one of the most important policy is 'Depends only on standard libraries.' (as README says) |
Beta Was this translation helpful? Give feedback.
-
Even though it is a great library, the final binary size is making it less attractive to use this library. Using
I guess this is due to the literal maps in https://github.com/yuin/goldmark/blob/master/util/html5entities.go and https://github.com/yuin/goldmark/blob/master/util/unicode_case_folding.go. I'm struggling with a similar issue in my code base but I'm not sure how to improve this. Apparently, having large literal maps excessively inflates the resulting binary. In this case the ~500kB is due to the map in html5entities.go, it doesn't matter if it's global or not. I guess you put this in a Results from some experiments:
Are you interested in this approach? I could generate a PR for you. |
Beta Was this translation helpful? Give feedback.
-
Here's an idea if the map is immutable once created. Rearrange the data into 2 arrays and a string. Then for each HTMLEntity only need to know how long the name, and how many CodePoints and Characters it needs to unpack. func main() {
var rows []uint8
var codePoints []int
var characters []byte
var names []byte
for _, v := range util.Html5entities() {
rows = append(rows, uint8(len(v.Name)), uint8(len(v.CodePoints)), uint8(len(v.Characters)))
names = append(names, v.Name...)
codePoints = append(codePoints, v.CodePoints...)
characters = append(characters, v.Characters...)
}
fmt.Println()
fmt.Println(`const rows = "" +`)
printGoString(os.Stdout, rows, 70)
fmt.Println()
fmt.Println(`const names = "" +`)
printGoString(os.Stdout, names, 70)
fmt.Println()
fmt.Printf(`var characters = %#v`, characters)
fmt.Println()
fmt.Printf("var codePoints = %#v", codePoints)
} The output above made into an experimental html5entities.go replacement. Due to the elimination of 6371 allocations, it constructs the map in a third of the time.
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently, this code base has a custom Unicode folding implemented in
util/unicode_case_folding.go
.But this feature has already been implemented with golang.org/x/text/cases.
I'm proposing switching to the golang/x package because, for one, the
golang.org/x/text/cases
implementation is much performant and smaller. We're usinggoldmark
in our application, and it is the biggest contributor to the binary size (themap
in theutils
package).Beta Was this translation helpful? Give feedback.
All reactions