Performance schema.tagValues vs function definition

Hi,

I am trying to find reasons for performance issues in some of my queries and run into some extreme differences between my own queries (taking the function definition) and queries from predefined packages.

The following Queries (package function and its function definition taken from schema.tagValues() function | Flux 0.x Documentation) take about 300ms (first query) and ~30s (second query) when executed with my sample data set.

import "influxdata/influxdb/schema"
schema.tagValues(bucket: "test-bucket",tag: "id")
tagValues = (bucket, tag, predicate=(r) => true, start=-30d) =>
  from(bucket: bucket)
    |> range(start: start)
    |> filter(fn: predicate)
    |> group(columns: [tag])
    |> distinct(column: tag)
    |> keep(columns: ["_value"])
tagValues(bucket: "test-bucket",tag: "id")

How come there is such a large difference between the function defined in the package and it’s corresponding function definition. Are there any ways to improve this?

Thank you very much for any help provided in advance.
Cheers,
Phili