vimamsa 0.1.27 → 0.1.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +139 -89
  3. data/custom_example.rb +18 -6
  4. data/doc/TODO.md +327 -110
  5. data/doc/action_names_plan.md +442 -0
  6. data/doc/bundling_plan.md +2 -1
  7. data/doc/delta_syntax_plan.md +293 -0
  8. data/doc/demo_recording_plan.md +288 -0
  9. data/doc/design_goals.md +27 -0
  10. data/doc/intro_page_plan.md +266 -0
  11. data/doc/key_bindings_report_plan.md +45 -0
  12. data/doc/line_tree_plan.md +89 -0
  13. data/doc/missing_vim_bindings.md +34 -44
  14. data/doc/modules_settings_plan.md +1 -1
  15. data/doc/registries_plan.md +202 -0
  16. data/doc/startup_speed_plan.md +97 -0
  17. data/doc/treap_visualizer.html +585 -0
  18. data/doc/vim_compatibility_plan.md +186 -31
  19. data/doc/vimlike_vim_conflicts.md +236 -228
  20. data/doc/vm_snapshots_plan.md +4 -4
  21. data/doc/wysiwyg_plan.md +231 -0
  22. data/exe/run_tests.rb +8 -1
  23. data/exe/vimamsa +49 -6
  24. data/help/intro.txt +30 -0
  25. data/help/vim_intro.txt +31 -0
  26. data/img/demo.gif +0 -0
  27. data/img/demo.mp4 +0 -0
  28. data/lang/hyperplaintext.lang +1 -1
  29. data/lib/vimamsa/ack.rb +2 -0
  30. data/lib/vimamsa/actions.rb +381 -36
  31. data/lib/vimamsa/bookmarks.rb +8 -8
  32. data/lib/vimamsa/buffer.rb +83 -37
  33. data/lib/vimamsa/buffer_changetext.rb +58 -36
  34. data/lib/vimamsa/buffer_list.rb +2 -2
  35. data/lib/vimamsa/buffer_manager.rb +6 -6
  36. data/lib/vimamsa/cli_help.rb +75 -0
  37. data/lib/vimamsa/clipboard.rb +6 -3
  38. data/lib/vimamsa/conf.rb +9 -0
  39. data/lib/vimamsa/crash_handler.rb +2 -2
  40. data/lib/vimamsa/debug.rb +2 -2
  41. data/lib/vimamsa/demo_player.rb +458 -0
  42. data/lib/vimamsa/demo_recorder.rb +277 -0
  43. data/lib/vimamsa/diff_buffer.rb +1 -1
  44. data/lib/vimamsa/dot_repeat.rb +104 -0
  45. data/lib/vimamsa/easy_jump.rb +54 -3
  46. data/lib/vimamsa/editor.rb +89 -46
  47. data/lib/vimamsa/file_history.rb +1 -1
  48. data/lib/vimamsa/file_manager.rb +23 -23
  49. data/lib/vimamsa/form_input.rb +388 -0
  50. data/lib/vimamsa/gui.rb +83 -13
  51. data/lib/vimamsa/gui_command_line.rb +44 -5
  52. data/lib/vimamsa/gui_form_generator.rb +17 -6
  53. data/lib/vimamsa/gui_key_hint.rb +165 -0
  54. data/lib/vimamsa/gui_keylog_panel.rb +164 -2
  55. data/lib/vimamsa/gui_menu.rb +69 -50
  56. data/lib/vimamsa/gui_select_window.rb +77 -43
  57. data/lib/vimamsa/gui_settings.rb +9 -5
  58. data/lib/vimamsa/gui_sourceview.rb +15 -81
  59. data/lib/vimamsa/gui_theme.rb +11 -2
  60. data/lib/vimamsa/hook.rb +2 -0
  61. data/lib/vimamsa/intro_page.rb +368 -0
  62. data/lib/vimamsa/key_actions.rb +315 -225
  63. data/lib/vimamsa/key_binding_tree.rb +228 -61
  64. data/lib/vimamsa/key_bindings_notepad.rb +18 -16
  65. data/lib/vimamsa/key_bindings_report.rb +290 -67
  66. data/lib/vimamsa/key_bindings_vim.rb +47 -297
  67. data/lib/vimamsa/key_bindings_vimlike.rb +347 -339
  68. data/lib/vimamsa/key_names.rb +80 -0
  69. data/lib/vimamsa/line_tree.rb +367 -0
  70. data/lib/vimamsa/macro.rb +20 -3
  71. data/lib/vimamsa/rbvma.rb +15 -0
  72. data/lib/vimamsa/registers.rb +125 -0
  73. data/lib/vimamsa/run_ruby.rb +64 -0
  74. data/lib/vimamsa/search_replace.rb +4 -4
  75. data/lib/vimamsa/string_util.rb +17 -3
  76. data/lib/vimamsa/tests.rb +8 -8
  77. data/lib/vimamsa/text_objects.rb +11 -54
  78. data/lib/vimamsa/text_transforms.rb +4 -0
  79. data/lib/vimamsa/tmp_user_dir.rb +39 -0
  80. data/lib/vimamsa/user_dirs.rb +83 -0
  81. data/lib/vimamsa/version.rb +1 -1
  82. data/lib/vimamsa/vim_core.rb +355 -0
  83. data/lib/vimamsa/vim_operators.rb +365 -0
  84. data/modules/calculator/calculator.rb +5 -5
  85. data/modules/color_highlight/color_highlight.rb +3 -3
  86. data/modules/dictation/dictation.rb +32 -32
  87. data/modules/ollama/ollama.rb +5 -5
  88. data/modules/terminal/terminal.rb +5 -5
  89. data/modules/tts/tts.rb +10 -10
  90. data/run_e2e_vm.sh +3 -3
  91. data/run_tests_vm.rb +138 -0
  92. data/scripts/demo/demo_easyjump_steps.txt +60 -0
  93. data/scripts/demo/demo_files_steps.txt +52 -0
  94. data/scripts/demo/demo_steps.txt +9 -1
  95. data/scripts/demo/notes.txt +6 -0
  96. data/scripts/demo/record_demo.rb +60 -81
  97. data/scripts/demo/report.rb +7 -0
  98. data/scripts/demo/shapes.rb +1 -0
  99. data/scripts/demo/square/shapes.rb +29 -0
  100. data/scripts/demo/square/steps.txt +185 -0
  101. data/scripts/lib/perf_startup.rb +138 -0
  102. data/scripts/lib/script_helpers.rb +53 -0
  103. data/scripts/perf_compare.rb +34 -0
  104. data/scripts/profile_startup.rb +72 -0
  105. data/tests/test_action_ids.rb +232 -0
  106. data/tests/test_auto_format.rb +2 -2
  107. data/tests/test_autocomplete.rb +1 -1
  108. data/tests/test_basic_editing.rb +18 -18
  109. data/tests/test_bookmarks.rb +6 -6
  110. data/tests/test_bracket_match.rb +3 -0
  111. data/tests/test_cli_help.rb +64 -0
  112. data/tests/test_color_highlight.rb +2 -2
  113. data/tests/test_command_line.rb +1 -1
  114. data/tests/test_context_menu_file.rb +18 -0
  115. data/tests/test_copy_paste.rb +33 -33
  116. data/tests/test_custom_two_phase.rb +1 -1
  117. data/tests/test_demo_player.rb +301 -0
  118. data/tests/test_demo_recorder.rb +202 -0
  119. data/tests/test_dictation.rb +16 -16
  120. data/tests/test_dot_repeat.rb +88 -0
  121. data/tests/test_easy_jump.rb +93 -0
  122. data/tests/test_extract_file_links.rb +3 -3
  123. data/tests/test_file_panel.rb +2 -2
  124. data/tests/test_flash.rb +1 -1
  125. data/tests/test_fold.rb +1 -1
  126. data/tests/test_form_input.rb +203 -0
  127. data/tests/test_func_panel.rb +2 -2
  128. data/tests/test_gtk_sync.rb +7 -7
  129. data/tests/test_intro_page.rb +437 -0
  130. data/tests/test_key_categories.rb +163 -0
  131. data/tests/test_keylog_panel.rb +163 -3
  132. data/tests/test_line_ends.rb +51 -0
  133. data/tests/test_line_tree.rb +86 -0
  134. data/tests/test_lsp_clangd.rb +2 -2
  135. data/tests/test_macro.rb +2 -2
  136. data/tests/test_module_interface.rb +9 -9
  137. data/tests/test_notepad_bindings.rb +5 -5
  138. data/tests/test_perf_startup.rb +28 -0
  139. data/tests/test_random_edit.rb +27 -27
  140. data/tests/test_registers.rb +122 -0
  141. data/tests/test_run_ruby.rb +77 -0
  142. data/tests/test_startup_file.rb +1 -1
  143. data/tests/test_text_objects.rb +1 -1
  144. data/tests/test_text_transforms.rb +12 -0
  145. data/tests/test_tmp_user_dir.rb +79 -0
  146. data/tests/test_tts.rb +10 -10
  147. data/tests/test_undo.rb +34 -34
  148. data/tests/test_user_dirs.rb +122 -0
  149. data/tests/test_vim_bindings.rb +107 -6
  150. data/tests/test_vim_conflicts.rb +41 -4
  151. data/tests/test_vim_operators.rb +116 -0
  152. data/tests/test_window_layout.rb +83 -0
  153. data/vimamsa.gemspec +1 -1
  154. data/vm_guest_run.sh +22 -2
  155. metadata +58 -3
  156. data/run_tests_vm.sh +0 -130
@@ -0,0 +1,185 @@
1
+ # Recorded with Help ▸ Demos ▸ Record demo (2026-11-21).
2
+ # Edit freely; the format is in scripts/demo/demo_steps.txt.
3
+ title square
4
+ file shapes.rb
5
+ delay 0.3
6
+ wait 0.3
7
+ # Jump to the start of the next word
8
+ keys w d
9
+ wait 1
10
+ # Delete to end of line (vim D), Switch to INSERT mode
11
+ keys O ctrl
12
+ type Hello World!!!
13
+ # Return to the previous mode
14
+ keys ctrl
15
+ # Move to the beginning of the current line
16
+ wait 0.5
17
+ keys 0
18
+ wait 0.2
19
+ # Move one line forward, Enter VISUAL mode (for selections), Move to the end of the buffer, Search actions
20
+ keys j v
21
+ delay 0.3
22
+ keys G
23
+ delay 0.3
24
+ keys , , s
25
+ wait 0.3
26
+ # A namespace and a fuzzy name: always the same action (the ranking of a
27
+ # plain fuzzy query depends on which actions exist)
28
+ type linerempempty
29
+ wait 0.5
30
+ # Form: submit, or press the focused button
31
+ keys enter
32
+ wait 0.5
33
+ # Move one line backward
34
+ keys k
35
+ wait 0.5
36
+ keys G
37
+ wait 0.2
38
+ keys X X X X
39
+ # Easy jump
40
+ keys s
41
+ target line 13 col 1
42
+ keys @JUMP_LABEL@
43
+ # Enter VISUAL mode (for selections)
44
+ keys v
45
+ # Easy jump
46
+ keys s
47
+ wait 0.4
48
+ target line 21 col 1
49
+ keys @JUMP_LABEL@
50
+ # Move to the end of the current line, Move backward one character, Copy selection to clipboard
51
+ keys O
52
+ delay 0.2
53
+ keys y
54
+ delay 0.2
55
+ keys h y
56
+ wait 0.5
57
+ # Insert an empty line below, Move one line backward, Paste text after the cursor
58
+ keys X X k X p
59
+ wait 0.5
60
+ # Easy jump
61
+ keys s
62
+ wait 0.3
63
+ target line 22 col 7
64
+ keys @JUMP_LABEL@
65
+ # Delete to the end of the word, Switch to INSERT mode
66
+ keys d e i
67
+ type Square
68
+ # Return to the previous mode
69
+ keys esc
70
+ wait 0.5
71
+ # Move one line forward, Move to the beginning of the current line, Enter VISUAL mode (for selections)
72
+ keys j 0 v
73
+ # Easy jump
74
+ keys s
75
+ wait 0.5
76
+ target line 30 col 1
77
+ keys @JUMP_LABEL@
78
+ # Move to the end of the current line, Move backward one character
79
+ keys O h , , r
80
+ wait 0.5
81
+ keys ,
82
+ wait 0.5
83
+ # Search and replace
84
+ keys r r
85
+ wait 0.5
86
+ type radius
87
+ # Form: next field or button
88
+ keys tab
89
+ type width
90
+ wait 0.4
91
+ # Form: submit, or press the focused button
92
+ keys enter
93
+ wait 0.5
94
+ # Move one line backward, Jump to the end of the next word
95
+ keys k k e
96
+ wait 0.5
97
+ target line 28 col 5
98
+ keys @JUMP_LABEL@
99
+ # Jump to the start of the previous word, Delete up to the next *, Delete char forward
100
+ keys d f *
101
+ wait 0.4
102
+ keys x
103
+ wait 0.2
104
+ # Move one line forward
105
+ keys j j
106
+ wait 0.2
107
+ keys j j j
108
+ wait 0.2
109
+ keys z z
110
+ wait 0.2
111
+ # Move one line backward, Jump to the start of the next word, Enter VISUAL mode (for selections), Move forward one character, Jump to the next ,, Move backward one character, Copy selection to clipboard, Move one line forward, Insert an empty line below, Paste text after the cursor, Move to the beginning of the current line, Copy the current line
112
+ keys w
113
+ wait 0.2
114
+ keys v l
115
+ wait 0.2
116
+ keys f , h
117
+ wait 0.2
118
+ keys y
119
+ wait 0.1
120
+ keys j
121
+ wait 0.2
122
+ keys X X
123
+ wait 0.2
124
+ keys p 0
125
+ wait 0.2
126
+ keys y y
127
+ wait 0.5
128
+ # Move to the end of the current line, Switch to INSERT mode
129
+ keys esc O i
130
+ type .area
131
+ # Return to the previous mode, Move to the beginning of the current line, Copy the current line, Paste text after the cursor
132
+ keys esc 0 y y p
133
+ wait 0.5
134
+ # Delete to the end of the word, Switch to INSERT mode
135
+ keys d e i
136
+ type AS
137
+ wait 0.3
138
+ # Delete backwards
139
+ keys backspace backspace
140
+ type Square
141
+ # Return to the previous mode
142
+ keys esc
143
+ wait 0.5
144
+ # Move one line backward
145
+ keys k
146
+ wait 0.5
147
+ # Join the next line to the current line, Move backward one character, Insert ,, Move to the beginning of the current line, Switch to INSERT mode
148
+ keys J h
149
+ wait 0.2
150
+ keys space ,
151
+ wait 0.2
152
+ keys 0
153
+ wait 0.2
154
+ keys i
155
+ type [
156
+ # Move to the end of the current line
157
+ keys ctrl-e
158
+ wait 0.5
159
+ type ]
160
+ wait 0.5
161
+ # Move to the beginning of the current line
162
+ keys ctrl-a
163
+ wait 1.1
164
+ # Return to the previous mode
165
+ keys esc
166
+ wait 1.1
167
+ # Move to the start of the buffer, Enter VISUAL mode (for selections), Move to the end of the buffer, Search actions
168
+ keys g g
169
+ wait 0.2
170
+ keys v G
171
+ wait 0.2
172
+ keys k k k
173
+ wait 0.2
174
+ keys , , s
175
+ wait 0.3
176
+ type evlalconver
177
+ wait 0.5
178
+ # Form: submit, or press the focused button
179
+ keys enter
180
+ wait 0.5
181
+ # Move one line forward
182
+ keys j j
183
+ wait 0.5
184
+
185
+
@@ -0,0 +1,138 @@
1
+ # Startup time of the editor, for comparing two versions (a performance
2
+ # regression check). Used by tests/test_perf_startup.rb and
3
+ # scripts/perf_compare.rb. Standard library only.
4
+ #
5
+ # Startup time = from starting exe/vimamsa until the editor has finished
6
+ # initializing (hook_custom_after_init, called at the end of Editor#start)
7
+ # and the main loop has run once (first idle), measured with the system-wide
8
+ # monotonic clock. Each version runs with its own throwaway config dir and the
9
+ # same file to open. Runs alternate between the versions, after a warm-up run
10
+ # of each, so a slow moment of the machine affects both. Versions are
11
+ # compared by their fastest run: other work on the machine only ever makes a
12
+ # run slower, so the fastest one is the least disturbed (the median is
13
+ # reported too).
14
+ require "tmpdir"
15
+ require "fileutils"
16
+ require "open3"
17
+ require "rbconfig"
18
+
19
+ module PerfStartup
20
+ module_function
21
+
22
+ def now
23
+ Process.clock_gettime(Process::CLOCK_MONOTONIC)
24
+ end
25
+
26
+ # A config dir whose custom.rb writes the time to <dir>/ready when the
27
+ # editor is up, and quits
28
+ def make_user_dir(dir)
29
+ FileUtils.mkdir_p(dir)
30
+ File.write(File.join(dir, "custom.rb"), <<~RUBY)
31
+ cnf.lsp.enabled = false
32
+ cnf.intro.show_on_startup = false # the same work as in older versions
33
+ def hook_custom_after_init
34
+ GLib::Idle.add {
35
+ File.write(#{File.join(dir, "ready").inspect}, Process.clock_gettime(Process::CLOCK_MONOTONIC).to_s)
36
+ GLib::Timeout.add(300) { vma.shutdown; false }
37
+ false
38
+ }
39
+ end
40
+ RUBY
41
+ dir
42
+ end
43
+
44
+ # Seconds until the editor in tree (a source checkout) was up
45
+ def startup_time(tree, user_dir, file: nil, timeout: 90)
46
+ ready = File.join(user_dir, "ready")
47
+ FileUtils.rm_f(ready)
48
+ t0 = now
49
+ pid = Process.spawn(RbConfig.ruby, File.join(tree, "exe/vimamsa"), "--user-dir", user_dir, *[file].compact,
50
+ out: File::NULL, err: File.join(user_dir, "log.txt"))
51
+ t = nil
52
+ loop {
53
+ if File.exist?(ready) && (s = File.read(ready)) != ""
54
+ t = s.to_f - t0
55
+ break
56
+ end
57
+ if Process.waitpid(pid, Process::WNOHANG)
58
+ pid = nil
59
+ raise "editor in #{tree} quit before it was up (log: #{user_dir}/log.txt)"
60
+ end
61
+ raise "editor in #{tree} not up after #{timeout} s (log: #{user_dir}/log.txt)" if now - t0 > timeout
62
+ sleep 0.01
63
+ }
64
+ # Let it quit by itself (custom.rb shuts it down)
65
+ t1 = now
66
+ while pid && Process.waitpid(pid, Process::WNOHANG).nil?
67
+ if now - t1 > 20
68
+ Process.kill("KILL", pid)
69
+ Process.wait(pid)
70
+ end
71
+ sleep 0.05
72
+ end
73
+ pid = nil
74
+ t
75
+ ensure
76
+ if pid
77
+ Process.kill("KILL", pid) rescue nil
78
+ Process.wait(pid) rescue nil
79
+ end
80
+ end
81
+
82
+ # Yields a checkout of ref (a temporary git worktree of repo). It gets this
83
+ # tree's compiled extension (lib/vmaext.so): its source isn't tracked, so
84
+ # an old commit can't be built.
85
+ def with_checkout(repo, ref)
86
+ dir = Dir.mktmpdir("vma-perf-ref")
87
+ FileUtils.rmdir(dir)
88
+ out, st = Open3.capture2e("git", "-C", repo, "worktree", "add", "--detach", "--force", dir, ref)
89
+ raise "git worktree add #{ref} failed: #{out}" if !st.success?
90
+ so = File.join(repo, "lib", "vmaext.so")
91
+ FileUtils.cp(so, File.join(dir, "lib")) if File.exist?(so)
92
+ yield dir
93
+ ensure
94
+ if dir && File.exist?(dir)
95
+ system("git", "-C", repo, "worktree", "remove", "--force", dir, out: File::NULL, err: File::NULL)
96
+ FileUtils.rm_rf(dir)
97
+ end
98
+ end
99
+
100
+ # { "current" => [seconds...], ref => [...] } for runs startups of each
101
+ def compare(repo, ref, runs: 5, file: nil, log: ->(s) { puts s })
102
+ Dir.mktmpdir("vma-perf") { |tmp|
103
+ with_checkout(repo, ref) { |old|
104
+ trees = { "current" => repo, ref => old }
105
+ dirs = trees.to_h { |name, _| [name, make_user_dir(File.join(tmp, name.gsub(/\W/, "_")))] }
106
+ times = trees.to_h { |name, _| [name, []] }
107
+ trees.each { |name, tree| startup_time(tree, dirs[name], file: file) } # warm-up
108
+ runs.times { |i|
109
+ trees.each { |name, tree|
110
+ t = startup_time(tree, dirs[name], file: file)
111
+ times[name] << t
112
+ log.(" run #{i + 1} #{name}: #{format("%.2f", t)} s")
113
+ }
114
+ }
115
+ times
116
+ }
117
+ }
118
+ end
119
+
120
+ def median(a)
121
+ s = a.sort
122
+ s.size.odd? ? s[s.size / 2] : (s[s.size / 2 - 1] + s[s.size / 2]) / 2.0
123
+ end
124
+
125
+ # The commit to compare with by default: the previous one, or the current
126
+ # commit when the working tree has uncommitted changes to the code (then
127
+ # those changes are what's being checked)
128
+ def default_ref(repo)
129
+ out, = Open3.capture2("git", "-C", repo, "status", "--porcelain", "--", "lib", "exe", "ext")
130
+ out.strip.empty? ? "HEAD~1" : "HEAD"
131
+ end
132
+
133
+ # Slower = the median grew by more than ratio and by more than min_secs
134
+ # (small absolute changes are noise)
135
+ def slower?(cur, ref, ratio: 0.25, min_secs: 0.3)
136
+ cur - ref > ref * ratio && cur - ref > min_secs
137
+ end
138
+ end
@@ -0,0 +1,53 @@
1
+ # Helpers shared by the project's Ruby scripts (run_tests_vm.rb, ...).
2
+ # Standard library only: the scripts run before any gems are installed.
3
+ require "open3"
4
+
5
+ module ScriptHelpers
6
+ module_function
7
+
8
+ # Print a step, as ">> msg"
9
+ def step(msg)
10
+ puts ">> #{msg}"
11
+ $stdout.flush
12
+ end
13
+
14
+ # Print an error, as "!! msg" (more lines indented), and exit with code
15
+ def fail!(msg, code = 1)
16
+ lines = msg.to_s.lines.map(&:chomp)
17
+ warn "!! #{lines.first}"
18
+ lines.drop(1).each { |l| warn " #{l}" }
19
+ exit code
20
+ end
21
+
22
+ # Run a command; on failure, exit with a message. label: what to call the
23
+ # command in the message (never the arguments, which may hold secrets).
24
+ def run!(*cmd, label: cmd.first, code: 1, **opts)
25
+ system(*cmd, **opts) || fail!("#{label} failed (exit #{$?.exitstatus})", code)
26
+ end
27
+
28
+ # Run a command, printing its output (stdout and stderr) as it comes, and
29
+ # return [output, Process::Status]
30
+ def run_streaming(*cmd)
31
+ out = +""
32
+ status = nil
33
+ Open3.popen2e(*cmd) { |stdin, oe, thr|
34
+ stdin.close
35
+ begin
36
+ loop {
37
+ chunk = oe.readpartial(4096)
38
+ $stdout.write(chunk)
39
+ $stdout.flush
40
+ out << chunk
41
+ }
42
+ rescue EOFError
43
+ end
44
+ status = thr.value
45
+ }
46
+ [out, status]
47
+ end
48
+
49
+ # The names of the environment variables that are unset or empty
50
+ def missing_env(*names)
51
+ names.select { |n| ENV[n].to_s.empty? }
52
+ end
53
+ end
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+ # Compare the editor's startup time with an earlier commit, on this machine
3
+ # (the same check as tests/test_perf_startup.rb, without the test runner).
4
+ # Opens editor windows on the current display, one after another.
5
+ #
6
+ # ruby scripts/perf_compare.rb [--ref REF] [--runs N]
7
+ # --ref commit to compare with (default: the previous commit, or the
8
+ # current one when lib/, exe/ or ext/ have uncommitted changes)
9
+ # --runs startups of each version (default 5)
10
+ #
11
+ # Exit code: 0 ok, 1 the current version starts much slower (fastest run
12
+ # more than 25% and 0.3 s slower).
13
+ require "optparse"
14
+ require_relative "lib/perf_startup"
15
+ require_relative "lib/script_helpers"
16
+ include ScriptHelpers
17
+
18
+ repo = File.expand_path("..", __dir__)
19
+ opts = { ref: nil, runs: 5 }
20
+ OptionParser.new { |o|
21
+ o.on("--ref REF") { |v| opts[:ref] = v }
22
+ o.on("--runs N", Integer) { |v| opts[:runs] = v }
23
+ }.parse!
24
+ fail!("--runs must be at least 1", 2) if opts[:runs] < 1
25
+ fail!("needs a display (DISPLAY or WAYLAND_DISPLAY)", 2) if missing_env("DISPLAY", "WAYLAND_DISPLAY").size == 2
26
+ ref = opts[:ref] || PerfStartup.default_ref(repo)
27
+
28
+ step "Startup time: current vs #{ref}, #{opts[:runs]} runs each"
29
+ times = PerfStartup.compare(repo, ref, runs: opts[:runs], file: File.join(repo, "README.md"))
30
+ cur, old = times["current"].min, times[ref].min
31
+ pct = (cur - old) / old * 100
32
+ step format("Fastest: current %.2f s, %s %.2f s (%+.0f%%)", cur, ref, old, pct)
33
+ step format("Median: current %.2f s, %s %.2f s", PerfStartup.median(times["current"]), ref, PerfStartup.median(times[ref]))
34
+ fail!(format("Startup is %.2f s slower than at %s", cur - old, ref), 1) if PerfStartup.slower?(cur, old)
@@ -0,0 +1,72 @@
1
+ # Where the editor's startup time goes. Loaded with -r before exe/vimamsa:
2
+ #
3
+ # ruby -r ./scripts/profile_startup.rb exe/vimamsa [file]
4
+ #
5
+ # Prints to stderr, at exit: the slow requires (a tree, > 10 ms) and, after
6
+ # the code is loaded, the slow calls of vimamsa's own methods (a tree, > 10
7
+ # ms, inclusive times), with their start offset from when this file was
8
+ # loaded. Tracing adds overhead, so method times are somewhat too high.
9
+ # Env: VMA_PROFILE_MIN_MS (10), VMA_PROFILE_DEPTH (6).
10
+ module StartupProfile
11
+ T0 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
12
+ MIN = (ENV["VMA_PROFILE_MIN_MS"] || 10).to_f / 1000
13
+ DEPTH = (ENV["VMA_PROFILE_DEPTH"] || 6).to_i
14
+ @lines = [] # [start, depth, text]
15
+ @rdepth = 0
16
+ @stack = []
17
+
18
+ def self.now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
19
+
20
+ def self.note(start, depth, dt, text)
21
+ @lines << [start, depth, dt, text] if dt >= MIN
22
+ end
23
+
24
+ def self.require_wrap(name)
25
+ t = now
26
+ @rdepth += 1
27
+ d = @rdepth
28
+ yield
29
+ ensure
30
+ @rdepth -= 1
31
+ note(t, d, now - t, "require #{name}")
32
+ end
33
+
34
+ OWN = %r{/(lib/vimamsa|modules|exe)/}
35
+ @tp = TracePoint.new(:call, :return) { |tp|
36
+ next unless OWN.match?(tp.path)
37
+ case tp.event
38
+ when :call
39
+ @stack << now
40
+ when :return
41
+ t = @stack.pop
42
+ next if t.nil?
43
+ d = @stack.size
44
+ next if d >= DEPTH
45
+ what = "#{tp.defined_class}##{tp.method_id}"
46
+ note(t, d + 1, now - t, "#{what} (#{tp.path.sub(%r{.*/(lib|modules|exe)/}, '\1/')}:#{tp.lineno})")
47
+ end
48
+ }
49
+
50
+ def self.report
51
+ @tp.disable
52
+ STDERR.puts "=== startup profile (offset s, inclusive ms) ==="
53
+ @lines.sort_by { |s, d, _, _| [s, d] }.each { |s, d, dt, text|
54
+ STDERR.puts format("%6.3f %7.1f %s%s", s - T0, dt * 1000, " " * (d - 1), text)
55
+ }
56
+ end
57
+
58
+ # Method calls are traced from when the code is loaded (tracing during the
59
+ # requires would slow them down a lot)
60
+ def self.start_tracing = @tp.enable
61
+ end
62
+
63
+ module Kernel
64
+ alias_method :__profile_require, :require
65
+ def require(name)
66
+ r = StartupProfile.require_wrap(name) { __profile_require(name) }
67
+ StartupProfile.start_tracing if name == "vimamsa"
68
+ r
69
+ end
70
+ end
71
+
72
+ at_exit { StartupProfile.report }