mirror of
https://github.com/neovim/neovim.git
synced 2026-04-28 10:14:06 +00:00
vim-patch:7.4.497 #2295
Problem: With some regexp patterns the NFA engine uses many states and
becomes very slow. To the user it looks like Vim freezes.
Solution: When the number of states reaches a limit fall back to the old
engine. (Christian Brabandt)
https://github.com/vim/vim/releases/tag/v7-4-497
Helped-by: David Bürgin <676c7473@gmail.com>
Helped-by: Justin M. Keyes <justinkz@gmail.com>
Helped-by: Scott Prager <splinterofchaos@gmail.com>
This commit is contained in:
committed by
Justin M. Keyes
parent
a69e464f70
commit
d3bb177f1e
67
test/benchmark/bench_re_freeze_spec.lua
Normal file
67
test/benchmark/bench_re_freeze_spec.lua
Normal file
@@ -0,0 +1,67 @@
|
||||
-- Test for benchmarking RE engine.
|
||||
|
||||
local helpers = require('test.functional.helpers')
|
||||
local feed, insert, source = helpers.feed, helpers.insert, helpers.source
|
||||
local clear, execute, wait = helpers.clear, helpers.execute, helpers.wait
|
||||
|
||||
-- Temporary file for gathering benchmarking results for each regexp engine.
|
||||
local result_file = 'benchmark.out'
|
||||
-- Fixture containing an HTML fragment that can make a search appear to freeze.
|
||||
local sample_file = 'test/benchmark/samples/re.freeze.txt'
|
||||
|
||||
-- Vim script code that does both the work and the benchmarking of that work.
|
||||
local measure_cmd =
|
||||
[[call Measure(%d, ']] .. sample_file .. [[', '\s\+\%%#\@<!$', '+5')]]
|
||||
local measure_script = [[
|
||||
func! Measure(re, file, pattern, arg)
|
||||
let sstart=reltime()
|
||||
|
||||
execute 'set re=' . a:re
|
||||
execute 'split' a:arg a:file
|
||||
call search(a:pattern, '', '', 10000)
|
||||
q!
|
||||
|
||||
$put =printf('file: %s, re: %d, time: %s', a:file, a:re, reltimestr(reltime(sstart)))
|
||||
endfunc]]
|
||||
|
||||
describe('regexp search', function()
|
||||
-- The test cases rely on a small Vim script, which we source here, and also
|
||||
-- on a temporary result file, which we prepare and write to disk.
|
||||
setup(function()
|
||||
clear()
|
||||
source(measure_script)
|
||||
insert('" Benchmark_results:')
|
||||
execute('write! ' .. result_file)
|
||||
end)
|
||||
|
||||
-- At the end of the test run we just print the contents of the result file
|
||||
-- for human inspection and promptly delete the file.
|
||||
teardown(function()
|
||||
print ''
|
||||
for line in io.lines(result_file) do
|
||||
print(line)
|
||||
end
|
||||
os.remove(result_file)
|
||||
end)
|
||||
|
||||
it('is working with regexpengine=0', function()
|
||||
local regexpengine = 0
|
||||
execute(string.format(measure_cmd, regexpengine))
|
||||
execute('write')
|
||||
wait()
|
||||
end)
|
||||
|
||||
it('is working with regexpengine=1', function()
|
||||
local regexpengine = 1
|
||||
execute(string.format(measure_cmd, regexpengine))
|
||||
execute('write')
|
||||
wait()
|
||||
end)
|
||||
|
||||
it('is working with regexpengine=2', function()
|
||||
local regexpengine = 2
|
||||
execute(string.format(measure_cmd, regexpengine))
|
||||
execute('write')
|
||||
wait()
|
||||
end)
|
||||
end)
|
||||
4
test/benchmark/preload.lua
Normal file
4
test/benchmark/preload.lua
Normal file
@@ -0,0 +1,4 @@
|
||||
-- Modules loaded here will not be cleared and reloaded by Busted.
|
||||
-- Busted started doing this to help provide more isolation. See issue #62
|
||||
-- for more information about this.
|
||||
local helpers = require('test.functional.helpers')
|
||||
6
test/benchmark/samples/re.freeze.txt
Normal file
6
test/benchmark/samples/re.freeze.txt
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user