Repository navigation
perf: apply six safe optimizations across core modules - #8
Merged
Merged
Conversation
- decoder.ts: memoize CP932 TextDecoder at module scope; was re-constructed on every valid multibyte pair, O(n) overhead for CP932 files - buffer.ts: hoist fatalDecoderSupported probe to module-level constant FATAL_DECODER_SUPPORTED; was re-evaluated (including a TextDecoder allocation) on every #searchUtf8 call - context.ts: parallelize bufNr + winId Vim IPC calls with Promise.all; removes one sequential round-trip on every start - context.ts: remove redundant first foldMerge in Custom.get(); was done solely to extract `name`, then the result was discarded - ddx.ts: parallelize fn.expand + fn.getcwd Vim IPC calls with Promise.all in restart() for both primary and anotherPath opens - app.ts: replace slice(-1)[0] with at(-1)! in getDdx; avoids a single-element array allocation on every dispatcher call Agent-Logs-Url: https://github.com/Shougo/ddx.vim/sessions/19fb8487-9d09-400d-9e14-a81b0e5142f6 Co-authored-by: Shougo <41495+Shougo@users.noreply.github.com>
…okup - decoder.ts: add comment explaining TextDecoder.decode() stateless behavior and Deno single-threaded safety for the memoized instance - context.ts: use consistent bracket notation for both userOptions and this.global name access in Custom.get(), with explanatory comment Agent-Logs-Url: https://github.com/Shougo/ddx.vim/sessions/19fb8487-9d09-400d-9e14-a81b0e5142f6 Co-authored-by: Shougo <41495+Shougo@users.noreply.github.com>
- Use dot notation for this.global.name (typed Partial<DdxOptions>) while keeping bracket notation only for untyped userOptions - Replace defaultDdxOptions().name with the literal "default" to avoid constructing the full defaults object just for one field Agent-Logs-Url: https://github.com/Shougo/ddx.vim/sessions/19fb8487-9d09-400d-9e14-a81b0e5142f6 Co-authored-by: Shougo <41495+Shougo@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Six safe, zero-behavior-change performance optimizations identified in a prior codebase analysis.
decoder.ts— MemoizegetCp932Decoder()at module scopePreviously,
getCp932Decoder()was called inside the byte-processing loop, constructing a newTextDecoder(via a label-probe loop that tries up to 5 encoding labels) for every valid CP932 two-byte pair. For a 1 MB CP932 binary, this could mean tens of thousands of unnecessaryTextDecoderconstructions.Now a single
CP932_DECODERconstant is created at module load time and reused across all calls. A comment explains why this is safe:TextDecoder.decode()without thestreamoption is stateless between calls, and Deno is single-threaded within an isolate.buffer.ts— HoistfatalDecoderSupportedprobe to module levelThe capability probe for fatal-mode
TextDecodersupport was an IIFE re-evaluated on every#searchUtf8call — i.e., everygetStringsrequest. It allocates aTextDecoderand calls.decode()each time.Now a module-level constant
FATAL_DECODER_SUPPORTEDholds the result, computed exactly once on module load.context.ts— ParallelizebufNr+winIdVim IPC callsfn.bufnrandfn.win_getidare independent calls. They were awaited sequentially, incurring two round-trips to Vim/Neovim beforestartcould proceed. Changed toPromise.all.context.ts— Remove redundant firstfoldMergeinCustom.get()Custom.get()previously ran a fullfoldMerge(spread-object allocation over all options fields) solely to readoptions.name, then discarded the entire result and ran a secondfoldMergefor the real return value.Replaced with a direct property lookup chain:
userOptions["name"] ?? this.global.name ?? "default". Bracket notation is used for the untypedRecord<string, unknown>userOptions; dot notation for the typedPartial<DdxOptions>this.global.ddx.ts— Parallelizefn.expand+fn.getcwdinrestart()fn.expand(path expansion) andfn.getcwd(working directory) are independent Vim IPC calls, awaited sequentially for both the primary path andanotherPath. Changed toPromise.allfor each pair.app.ts— Replaceslice(-1)[0]withat(-1)!ingetDdxArray.prototype.slice(-1)allocates a new single-element array. This is called by virtually every dispatcher function (start,restart,redraw,uiAction,analyze,change,jump,getDiff,getStrings).at(-1)reads the last element directly without allocation.