1616 - [ Lazyload Colorizer with Lazy.nvim] ( #lazyload-colorizer-with-lazynvim )
1717 - [ Tailwind] ( #tailwind )
1818 - [ Testing] ( #testing )
19+ - [ Minimal Colorizer] ( #minimal-colorizer )
20+ - [ Trie] ( #trie )
21+ - [ Test] ( #test )
22+ - [ Benchmark] ( #benchmark )
23+ - [ Results] ( #results )
1924 - [ Extras] ( #extras )
2025 - [ TODO] ( #todo )
2126 <!-- toc:end-->
@@ -114,10 +119,8 @@ library to do custom highlighting themselves.
114119
115120``` lua
116121 require (" colorizer" ).setup ({
117- -- Filetype options. Accepts table like `user_default_options`
118- filetypes = { " *" },
119- -- Buftype options. Accepts table like `user_default_options`
120- buftypes = {},
122+ filetypes = { " *" }, -- Filetype options. Accepts table like `user_default_options`
123+ buftypes = {}, -- Buftype options. Accepts table like `user_default_options`
121124 -- Boolean | List of usercommands to enable. See User commands section.
122125 user_commands = true , -- Enable all or some usercommands
123126 lazy_load = false , -- Lazily schedule buffer highlighting setup function
@@ -144,19 +147,18 @@ library to do custom highlighting themselves.
144147 css = false , -- Enable all CSS *features*:
145148 -- names, RGB, RGBA, RRGGBB, RRGGBBAA, AARRGGBB, rgb_fn, hsl_fn
146149 css_fn = false , -- Enable all CSS *functions*: rgb_fn, hsl_fn
147- -- Highlighting mode. 'background'|'foreground'|'virtualtext'
148- mode = " background" , -- Set the display mode
149- -- Tailwind colors. boolean|'normal'|'lsp'|'both'. True is same as normal
150+ -- Tailwind colors. boolean|'normal'|'lsp'|'both'. True sets to 'normal'
150151 tailwind = false , -- Enable tailwind colors
151152 tailwind_opts = { -- Options for highlighting tailwind names
152- update_names = false , -- When using tailwind = 'both', update tailwind
153- -- names from LSP results. See tailwind section
153+ update_names = false , -- When using tailwind = 'both', update tailwind names from LSP results. See tailwind section
154154 },
155155 -- parsers can contain values used in `user_default_options`
156156 sass = { enable = false , parsers = { " css" } }, -- Enable sass colors
157+ -- Highlighting mode. 'background'|'foreground'|'virtualtext'
158+ mode = " background" , -- Set the display mode
157159 -- Virtualtext character to use
158160 virtualtext = " ■" ,
159- -- Display virtualtext inline with color
161+ -- Display virtualtext inline with color. boolean|'before'|'after'. True sets to 'after'
160162 virtualtext_inline = false ,
161163 -- Virtualtext highlight mode: 'background'|'foreground'
162164 virtualtext_mode = " foreground" ,
@@ -167,14 +169,6 @@ library to do custom highlighting themselves.
167169 })
168170```
169171
170- Highlighting modes:
171-
172- - ` background ` : sets the background text color.
173- - ` foreground ` : sets the foreground text color.
174- - ` virtualtext ` : indicate the color behind the virtualtext.
175-
176- Virtualtext symbol can be displayed at end of line, or
177-
178172Setup examples:
179173
180174``` lua
@@ -379,20 +373,116 @@ are cached and returned on `WinScrolled` event.
379373
380374## Testing
381375
382- For troubleshooting use ` test/minimal.lua ` .
383- Startup neovim with ` nvim --clean -u minimal.lua ` in the ` test ` directory.
376+ ### Minimal Colorizer
384377
385- Alternatively, use the following script from root directory:
378+ For troubleshooting use ` test/minimal-colorizer.lua ` .
379+ Startup neovim with ` nvim --clean -u minimal-colorizer.lua ` in the ` test ` directory.
380+
381+ Alternatively,
386382
387383``` bash
388- scripts/start_minimal.sh
384+ make minimal
385+ ```
386+
387+ or
388+
389+ ``` bash
390+ scripts/minimal-colorizer.sh
389391```
390392
391393To test colorization with your config, edit ` test/expect.lua ` to see expected
392394highlights.
393395The returned table of ` user_default_options ` from ` text/expect.lua ` will be used
394396to conveniently reattach Colorizer to ` test/expect.lua ` on save.
395397
398+ ### Trie
399+
400+ Colorizer uses a space efficient LuaJIT Trie implementation, which starts with
401+ an initial node capacity of 8 bytes and expands capacity per node when needed.
402+
403+ The trie can be tested and benchmarked using ` test/trie/test.lua ` and
404+ ` test/trie/benchmark.lua ` respectively.
405+
406+ #### Test
407+
408+ ``` bash
409+ # runs both trie-test and trie-benchmark targets
410+ make trie
411+ ```
412+
413+ ``` bash
414+ # runs trie test which inserts words and checks longest prefix
415+ make trie-test
416+ ```
417+
418+ #### Benchmark
419+
420+ ``` bash
421+ scripts/trie-test.sh
422+ ```
423+
424+ ``` bash
425+ # runs benchmark for different node initial capacity allocation
426+ make trie-benchmark
427+ ```
428+
429+ ``` bash
430+ scripts/trie-benchmark.sh
431+ ```
432+
433+ ##### Results
434+
435+ Inserting 7245 words: using uppercase, lowercase, camelcase from ` vim.api.nvim_get_color_map() ` and Tailwind colors
436+
437+ | Initial Capacity | Resize Count | Insert Time (ms) | Lookup Time (ms) |
438+ | ---------------- | ------------ | ---------------- | ---------------- |
439+ | 1 | 3652 | 25 | 16 |
440+ | 2 | 2056 | 11 | 8 |
441+ | 4 | 1174 | 6 | 5 |
442+ | 8 | 576 | 7 | 5 |
443+ | 16 | 23 | 7 | 5 |
444+ | 32 | 1 | 8 | 6 |
445+ | 64 | 0 | 10 | 7 |
446+
447+ Inserting 1000 randomized words
448+
449+ | Initial Capacity | Resize Count | Insert Time (ms) | Lookup Time (ms) |
450+ | ---------------- | ------------ | ---------------- | ---------------- |
451+ | 1 | 434 | 1 | 0 |
452+ | 2 | 234 | 1 | 1 |
453+ | 4 | 129 | 1 | 0 |
454+ | 8 | 51 | 1 | 0 |
455+ | 16 | 17 | 1 | 1 |
456+ | 32 | 3 | 1 | 2 |
457+ | 64 | 1 | 2 | 1 |
458+ | 128 | 0 | 4 | 1 |
459+
460+ Inserting 10,000 randomized words
461+
462+ | Initial Capacity | Resize Count | Insert Time (ms) | Lookup Time (ms) |
463+ | ---------------- | ------------ | ---------------- | ---------------- |
464+ | 1 | 4614 | 9 | 7 |
465+ | 2 | 2106 | 8 | 8 |
466+ | 4 | 842 | 9 | 7 |
467+ | 8 | 362 | 9 | 8 |
468+ | 16 | 208 | 11 | 9 |
469+ | 32 | 113 | 14 | 11 |
470+ | 64 | 24 | 21 | 14 |
471+ | 128 | 0 | 34 | 25 |
472+
473+ Inserting 100,000 randomized words
474+
475+ | Initial Capacity | Resize Count | Insert Time (ms) | Lookup Time (ms) |
476+ | ---------------- | ------------ | ---------------- | ---------------- |
477+ | 1 | 40656 | 160 | 117 |
478+ | 2 | 21367 | 116 | 111 |
479+ | 4 | 11604 | 122 | 109 |
480+ | 8 | 5549 | 133 | 113 |
481+ | 16 | 1954 | 141 | 138 |
482+ | 32 | 499 | 173 | 158 |
483+ | 64 | 100 | 233 | 173 |
484+ | 128 | 0 | 343 | 198 |
485+
396486## Extras
397487
398488Documentation is generated using ldoc. See
@@ -402,6 +492,5 @@ Documentation is generated using ldoc. See
402492
403493- [ ] Add more color types ( var, advanced css functions )
404494- [ ] Add more display modes. E.g - sign column
405- - [ ] Use a more space efficient trie implementation.
406495- [ ] Support custom parsers
407496- [ ] Options support providing function to enable/disable instead of just boolean
0 commit comments