Skip to content

Add cache for binary search in lines-map #640

Description

@5nord

The method syntax.Node.Span uses binary search to convert a file offset into a line number.
Location heavy tools, like our language server or formatter, would benefit from line-caches. For example like so:

func (t *tree) position(pos int) Position {
    if t.cachedLineBegin <= pos && pos < t.cachedLineEnd {
        line = t.cachedLine
    }
   // ...
}

To be efficient we probably need two separate line-caches, one for n.Pos() and one for n.End(). Best would be creating benchmarks comparing random position access, accessing only begin-offsets and accessing whole spans (begin- and end-offset).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions