Conversation
src/context.ts
Outdated
| const lineNumber = | ||
| lastIndice != null && index >= lastIndice | ||
| ? this.lineStartIndices.length | ||
| : this.lineStartIndices.findIndex((el) => index < el); |
There was a problem hiding this comment.
Thank you for this PR!
When I tried it previously, I found that this change had worse performance than sortedLastIndex.
ESLint core only makes limited use of sortedLastIndex, but this package is called for every node and token.
Could you change the search logic to be more similar to lodash?
There was a problem hiding this comment.
I have thought of switch lodash to remeda: https://github.com/remeda/remeda/blob/main/src/sortedLastIndex.ts
But remeda has an installation size of 2 MiB which is still not ideal.
I have also thought of the lodash.sortedlastindex standalone package.
Maybe I should just copy the O(log n) implementation from remeda.
There was a problem hiding this comment.
@ota-meshi I have added the implementation of sortedlastindex in 0aed79e (#210).
All tests still pass locally:
🦋 Changeset detectedLatest commit: 0aed79e The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
See also ota-meshi/eslint-plugin-yml#406
yaml-eslint-parseris the last package in myeslint-config-sukkathat depends onlodash.It turns out that we actually don't even need
sortedLastIndexat all. Instead, I replace it with a modified version of ESLint's implementation ofcontext.sourceCode.getLocFromIndex, and all tests still pass on my machine: