Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support nvim-0.7's nvim_set_hl api #132

Merged
merged 4 commits into from
Apr 18, 2022
Merged

Support nvim-0.7's nvim_set_hl api #132

merged 4 commits into from
Apr 18, 2022

Conversation

EdenEast
Copy link
Owner

@EdenEast EdenEast commented Apr 18, 2022

This pr adds support for nvim 0.7's new api nvim_set_hl. This pr also extends the compiler generate both a viml version and a nvim-0.7+ version. Nightfox will check if your editor is nvim-0.7+ before loading the correct precompiled file. When the user uses the compiler it also generates based on the editor's supported api.

Performance Note

From my initial testing there is no significant difference between the viml version and nvim_set_hi version when dealing with compiled files. Slightly more of the time the viml version is faster. I have tried to benchmark/time this with different methods:

Unsure that there is any benifit from this pr. It would be great of others could assist in coming up with a way to validate that nvim_set_hl version is faster.

Resolves: #131

@EdenEast EdenEast added enhancement New feature or request compiler Change relating to style compiler labels Apr 18, 2022
@EdenEast EdenEast self-assigned this Apr 18, 2022
@EdenEast
Copy link
Owner Author

Benchmarked requireing the two types of compiled files with the commited benchmark.

Benchmark
local benchmark = require("plenary.profile").benchmark
local fmt = string.format

local bench_iter = 100
local process_iter = 20

local function rep(n, char)
  local s = ""
  char = char or "-"
  for _ = 1, n do
    s = s .. char
  end
  return s
end

local function process(iterations)
  local function execute(modname)
    package.loaded[modname] = nil
    require(modname)
  end

  local nvim = benchmark(iterations, execute, "nightfox.precompiled.nvim.nightfox_compiled")
  local viml = benchmark(iterations, execute, "nightfox.precompiled.viml.nightfox_compiled")

  local difference = math.abs(nvim - viml)

  return nvim, viml, difference
end

local fmt_str = "| %-12s | %-12s | %-6s | %-12s |"
local lines = {}
table.insert(lines, fmt(fmt_str, "nvim", "viml", "winner", "difference"))
table.insert(lines, fmt(fmt_str, rep(12), rep(12), rep(6), rep(12)))
for _ = 1, process_iter do
  local nvim, viml, difference = process(bench_iter)
  local winner = viml > nvim and "nvim" or "viml"
  table.insert(lines, fmt(fmt_str, nvim, viml, winner, difference))
end

print(table.concat(lines, "\n"))

The results of this were:

nvim viml winner difference
0.13587727 0.14480916 nvim 0.00893189
0.126019095 0.144379504 nvim 0.018360409
0.121695834 0.145396634 nvim 0.0237008
0.126382063 0.147077075 nvim 0.020695012
0.126739153 0.15228737 nvim 0.025548217
0.123327316 0.144052505 nvim 0.020725189
0.120775092 0.144650431 nvim 0.023875339
0.122740701 0.144309368 nvim 0.021568667
0.120412961 0.142972085 nvim 0.022559124
0.120056512 0.143038069 nvim 0.022981557
0.121483176 0.143661078 nvim 0.022177902
0.121731856 0.146417584 nvim 0.024685728
0.124857722 0.143044062 nvim 0.01818634
0.121358067 0.142138951 nvim 0.020780884
0.121309499 0.146483703 nvim 0.025174204
0.120200838 0.143400906 nvim 0.023200068
0.121330985 0.143589931 nvim 0.022258946
0.122106515 0.143682243 nvim 0.021575728
0.126486296 0.14283298 nvim 0.016346684
0.120689742 0.143274019 nvim 0.022584277

From this I can see a small marginal improvement.

@EdenEast EdenEast merged commit dc2db5e into main Apr 18, 2022
@EdenEast EdenEast deleted the feat/0.7-api branch April 18, 2022 23:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler Change relating to style compiler enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant