Skip to content

update_text_document performs redundant unquote and dict lookups #612

@meymchen

Description

@meymchen

Component

pygls/workspace/workspace.py

Summary

update_text_document calls unquote(doc_uri) and self._text_documents[...] twice in succession on every text change, which can be very frequent during normal editing.

Steps to Reproduce

  1. Type a single character in a document.
  2. didChange triggers two identical unquote and dictionary lookups.

Expected Behavior

Single lookup and unquote per edit.

Actual Behavior

Redundant operations on the hot path.

Affected Code (pygls/workspace/workspace.py, ~L280-282)

self._text_documents[unquote(doc_uri)].apply_change(change)
self._text_documents[unquote(doc_uri)].version = text_doc.version

Proposed Fix

doc = self._text_documents[unquote(doc_uri)]
doc.apply_change(change)
doc.version = text_doc.version

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions