Skip to content

Question: Should TreeSitter.create() / newParser() used with multiple threads? #12

@sshaaf

Description

@sshaaf
  1. Is TreeSitter.create() / newParser() intended to be thread-safe when called concurrently on one instance?
  2. If not, should TreeSitter be per-thread (or per-task), or is there a recommended pattern for parallel batch parsing?
  TreeSitter ts = TreeSitter.create();
  try (var executor = Executors.newVirtualThreadPerTaskExecutor()) {
      for (Path file : javaFiles) {
          executor.submit(() -> {
              String source = Files.readString(file);
              TreeSitterParser parser = ts.newParser();
              parser.setLanguage(Language.JAVA);
              TreeSitterTree tree = parser.parseString(source);
              tree.close();
              parser.close();
          });
      }
  }

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