Skip to content

Add cache for binary search in lines-map #640

@5nord

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).

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