Add emoji support #1892

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
2 participants
@bep
Member

bep commented Feb 24, 2016

This uses the Emoji map from https://github.com/kyokomi/emoji -- but with a custom replacement implementation.

The built-in are fine for most use cases, but in Hugo we do care about pure speed.

The benchmarks below are skewed in Hugo's direction as the source and result is a byte slice,
Kyokomi's implementation works best with strings.

Curious: The easy-to-use strings.Replacer is also plenty fast.

BenchmarkEmojiKyokomiFprint-4      20000         86038 ns/op       33960 B/op        117 allocs/op
BenchmarkEmojiKyokomiSprint-4      20000         83252 ns/op       38232 B/op        122 allocs/op
BenchmarkEmojiStringsReplacer-4   100000         21092 ns/op       17248 B/op         25 allocs/op
BenchmarkHugoEmoji-4              500000          5728 ns/op         624 B/op         13 allocs/op

Fixes #1891

@bep bep changed the title from WIP: Add emoji support to Add emoji support Mar 2, 2016

@bep bep added the NeedsReview label Mar 2, 2016

@bep bep added this to the v0.16 milestone Mar 2, 2016

@moorereason

View changes

docs/content/templates/functions.md
+
+See the [Emoji cheat sheet](http://www.emoji-cheat-sheet.com/) for available emoticons.
+
+e.g. `{{ .Title | emojify }}`

This comment has been minimized.

@moorereason

moorereason Mar 11, 2016

Member

How about this example instead?

{{ "I :heart: Hugo" | emojify }}
@moorereason

moorereason Mar 11, 2016

Member

How about this example instead?

{{ "I :heart: Hugo" | emojify }}

This comment has been minimized.

@bep

bep Mar 11, 2016

Member

Me like.

@bep

bep Mar 11, 2016

Member

Me like.

+ }
+ }
+
+}

This comment has been minimized.

@moorereason

moorereason Mar 11, 2016

Member

Can we avoid using init and running this code when EnableEmoji == false?

Untested idea:

  • Change init to initEmojify and call at the top of Emojify.
  • Let emojis be nil until initEmojify is called.
  • Return early in initEmojify is emojis != nil.
@moorereason

moorereason Mar 11, 2016

Member

Can we avoid using init and running this code when EnableEmoji == false?

Untested idea:

  • Change init to initEmojify and call at the top of Emojify.
  • Let emojis be nil until initEmojify is called.
  • Return early in initEmojify is emojis != nil.

This comment has been minimized.

@bep

bep Mar 11, 2016

Member

The obvious alternative to init is sync.Once. No real runtime savings ... Remember, this is also called from a template tunc.

The if nil checks are all racy, me think. But an sync.Once is simple to do and safe.

@bep

bep Mar 11, 2016

Member

The obvious alternative to init is sync.Once. No real runtime savings ... Remember, this is also called from a template tunc.

The if nil checks are all racy, me think. But an sync.Once is simple to do and safe.

This comment has been minimized.

@bep

bep Mar 11, 2016

Member

Also: I will remove the strings.Replacer stuff. I was just curious about its performance.

@bep

bep Mar 11, 2016

Member

Also: I will remove the strings.Replacer stuff. I was just curious about its performance.

Add emoji support
This uses the Emoji map from https://github.com/kyokomi/emoji -- but with a custom replacement implementation.

The built-in are fine for most use cases, but in Hugo we do care about pure speed.

The benchmarks below are skewed in Hugo's direction as the source and result is a byte slice,
Kyokomi's implementation works best with strings.

Curious: The easy-to-use `strings.Replacer` is also plenty fast.

```
BenchmarkEmojiKyokomiFprint-4  	   20000	     86038 ns/op	   33960 B/op	     117 allocs/op
BenchmarkEmojiKyokomiSprint-4  	   20000	     83252 ns/op	   38232 B/op	     122 allocs/op
BenchmarkEmojiStringsReplacer-4	  100000	     21092 ns/op	   17248 B/op	      25 allocs/op
BenchmarkHugoEmoji-4           	  500000	      5728 ns/op	     624 B/op	      13 allocs/op
```

Fixes #1891
@bep

This comment has been minimized.

Show comment
Hide comment
@bep

bep Mar 11, 2016

Member

@moorereason I have adjusted re your comments. Please merge if you think it looks OK.

Member

bep commented Mar 11, 2016

@moorereason I have adjusted re your comments. Please merge if you think it looks OK.

@moorereason

This comment has been minimized.

Show comment
Hide comment
@moorereason

moorereason Mar 11, 2016

Member

👍 Merged in cafb784.

Member

moorereason commented Mar 11, 2016

👍 Merged in cafb784.

@bep bep removed the NeedsReview label Mar 11, 2016

@bep bep deleted the bep:emoji branch Apr 18, 2017

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