linter: gocritic - Highly extensible Go source code linter providing checks currently missing from other linters.
group: performance - Performance checks tell you about potential issues that can make your code run slower than it could be.
checker: rangeValCopy - Detects loops that copy big objects during each iteration. Suggests to use index access or take address and make use pointer instead.
Example
Before:
xs := make([][1024]byte, length)
for _, x := range xs {
// Loop body.
}
After:
xs := make([][1024]byte, length)
for i := range xs {
x := &xs[i]
// Loop body.
}
Expected output
Decision about enabling or not enabling this checker.
Findings
For this checker, the following findings were found in the current codebase:
migrations/inputs_cassandra/migration.go:156:2 gocritic rangeValCopy: each iteration copies 392 bytes (consider pointers or indexing)
models/filter_test.go:740:2 gocritic rangeValCopy: each iteration copies 392 bytes (consider pointers or indexing)
plugins/common/jolokia2/gatherer.go:51:2 gocritic rangeValCopy: each iteration copies 184 bytes (consider pointers or indexing)
plugins/common/jolokia2/gatherer.go:199:2 gocritic rangeValCopy: each iteration copies 184 bytes (consider pointers or indexing)
plugins/common/opcua/input/input_client.go:312:2 gocritic rangeValCopy: each iteration copies 160 bytes (consider pointers or indexing)
plugins/common/opcua/input/input_client.go:345:3 gocritic rangeValCopy: each iteration copies 160 bytes (consider pointers or indexing)
plugins/common/opcua/input/input_client.go:373:2 gocritic rangeValCopy: each iteration copies 200 bytes (consider pointers or indexing)
plugins/common/opcua/input/input_client.go:386:2 gocritic rangeValCopy: each iteration copies 200 bytes (consider pointers or indexing)
plugins/inputs/activemq/activemq.go:165:2 gocritic rangeValCopy: each iteration copies 152 bytes (consider pointers or indexing)
plugins/inputs/activemq/activemq.go:183:2 gocritic rangeValCopy: each iteration copies 152 bytes (consider pointers or indexing)
plugins/inputs/activemq/activemq.go:201:2 gocritic rangeValCopy: each iteration copies 232 bytes (consider pointers or indexing)
plugins/inputs/amd_rocm_smi/amd_rocm_smi.go:134:2 gocritic rangeValCopy: each iteration copies 1024 bytes (consider pointers or indexing)
plugins/inputs/ceph/ceph.go:625:2 gocritic rangeValCopy: each iteration copies 128 bytes (consider pointers or indexing)
plugins/inputs/couchbase/couchbase.go:113:4 gocritic rangeValCopy: each iteration copies 193 bytes (consider pointers or indexing)
plugins/inputs/cpu/cpu.go:137:4 gocritic rangeValCopy: each iteration copies 176 bytes (consider pointers or indexing)
plugins/inputs/ctrlx_datalayer/ctrlx_datalayer.go:315:2 gocritic rangeValCopy: each iteration copies 137 bytes (consider pointers or indexing)
plugins/inputs/diskio/diskio.go:58:2 gocritic rangeValCopy: each iteration copies 136 bytes (consider pointers or indexing)
plugins/inputs/docker/docker.go:237:2 gocritic rangeValCopy: each iteration copies 224 bytes (consider pointers or indexing)
plugins/inputs/docker/docker.go:282:3 gocritic rangeValCopy: each iteration copies 408 bytes (consider pointers or indexing)
plugins/inputs/docker/docker.go:288:3 gocritic rangeValCopy: each iteration copies 440 bytes (consider pointers or indexing)
plugins/inputs/docker/docker.go:298:3 gocritic rangeValCopy: each iteration copies 400 bytes (consider pointers or indexing)
plugins/inputs/docker_log/docker_log.go:206:2 gocritic rangeValCopy: each iteration copies 224 bytes (consider pointers or indexing)
plugins/inputs/ecs/ecs.go:160:2 gocritic rangeValCopy: each iteration copies 792 bytes (consider pointers or indexing)
plugins/inputs/ecs/types.go:65:2 gocritic rangeValCopy: each iteration copies 792 bytes (consider pointers or indexing)
plugins/inputs/elasticsearch_query/elasticsearch_query.go:78:2 gocritic rangeValCopy: each iteration copies 208 bytes (consider pointers or indexing)
plugins/inputs/elasticsearch_query/elasticsearch_query.go:184:2 gocritic rangeValCopy: each iteration copies 208 bytes (consider pointers or indexing)
plugins/inputs/fluentd/fluentd.go:123:2 gocritic rangeValCopy: each iteration copies 160 bytes (consider pointers or indexing)
plugins/inputs/gnmi/gnmi.go:174:2 gocritic rangeValCopy: each iteration copies 144 bytes (consider pointers or indexing)
plugins/inputs/gnmi/gnmi.go:263:2 gocritic rangeValCopy: each iteration copies 144 bytes (consider pointers or indexing)
plugins/inputs/gnmi/handler.go:184:3 gocritic rangeValCopy: each iteration copies 144 bytes (consider pointers or indexing)
plugins/inputs/gnmi/tag_store.go:31:2 gocritic rangeValCopy: each iteration copies 144 bytes (consider pointers or indexing)
plugins/inputs/intel_pmt/filtering.go:134:2 gocritic rangeValCopy: each iteration copies 184 bytes (consider pointers or indexing)
plugins/inputs/intel_pmt/filtering.go:155:2 gocritic rangeValCopy: each iteration copies 184 bytes (consider pointers or indexing)
plugins/inputs/intel_pmt/intel_pmt.go:307:2 gocritic rangeValCopy: each iteration copies 184 bytes (consider pointers or indexing)
plugins/inputs/intel_pmt/tags_extraction.go:16:2 gocritic rangeValCopy: each iteration copies 184 bytes (consider pointers or indexing)
plugins/inputs/intel_pmt/xml_parser.go:203:2 gocritic rangeValCopy: each iteration copies 128 bytes (consider pointers or indexing)
plugins/inputs/intel_pmu/intel_pmu.go:227:2 gocritic rangeValCopy: each iteration copies 136 bytes (consider pointers or indexing)
plugins/inputs/intel_pmu/intel_pmu.go:407:2 gocritic rangeValCopy: each iteration copies 136 bytes (consider pointers or indexing)
plugins/inputs/kafka_consumer/kafka_consumer.go:239:3 gocritic rangeValCopy: each iteration copies 153 bytes (consider pointers or indexing)
plugins/inputs/kube_inventory/certificate.go:21:2 gocritic rangeValCopy: each iteration copies 304 bytes (consider pointers or indexing)
plugins/inputs/kube_inventory/daemonset.go:17:2 gocritic rangeValCopy: each iteration copies 1160 bytes (consider pointers or indexing)
plugins/inputs/kube_inventory/deployment.go:16:2 gocritic rangeValCopy: each iteration copies 1176 bytes (consider pointers or indexing)
plugins/inputs/kube_inventory/endpoint.go:17:2 gocritic rangeValCopy: each iteration copies 288 bytes (consider pointers or indexing)
plugins/inputs/kube_inventory/ingress.go:17:2 gocritic rangeValCopy: each iteration copies 352 bytes (consider pointers or indexing)
plugins/inputs/kube_inventory/node.go:20:2 gocritic rangeValCopy: each iteration copies 704 bytes (consider pointers or indexing)
plugins/inputs/kube_inventory/persistentvolume.go:18:2 gocritic rangeValCopy: each iteration copies 608 bytes (consider pointers or indexing)
plugins/inputs/kube_inventory/persistentvolumeclaim.go:18:2 gocritic rangeValCopy: each iteration copies 472 bytes (consider pointers or indexing)
plugins/inputs/kube_inventory/pod.go:28:2 gocritic rangeValCopy: each iteration copies 1112 bytes (consider pointers or indexing)
plugins/inputs/kube_inventory/pod.go:44:2 gocritic rangeValCopy: each iteration copies 379 bytes (consider pointers or indexing)
plugins/inputs/kube_inventory/resourcequotas.go:18:2 gocritic rangeValCopy: each iteration copies 320 bytes (consider pointers or indexing)
plugins/inputs/kube_inventory/service.go:17:2 gocritic rangeValCopy: each iteration copies 584 bytes (consider pointers or indexing)
plugins/inputs/kube_inventory/statefulset.go:17:2 gocritic rangeValCopy: each iteration copies 1260 bytes (consider pointers or indexing)
plugins/inputs/kubernetes/kubernetes.go:130:2 gocritic rangeValCopy: each iteration copies 704 bytes (consider pointers or indexing)
plugins/inputs/kubernetes/kubernetes.go:177:2 gocritic rangeValCopy: each iteration copies 200 bytes (consider pointers or indexing)
plugins/inputs/kubernetes/kubernetes.go:288:2 gocritic rangeValCopy: each iteration copies 144 bytes (consider pointers or indexing)
plugins/inputs/kubernetes/kubernetes.go:304:3 gocritic rangeValCopy: each iteration copies 200 bytes (consider pointers or indexing)
plugins/inputs/logstash/logstash.go:419:2 gocritic rangeValCopy: each iteration copies 184 bytes (consider pointers or indexing)
plugins/inputs/mailchimp/mailchimp.go:53:3 gocritic rangeValCopy: each iteration copies 360 bytes (consider pointers or indexing)
plugins/inputs/mongodb/mongostat.go:1476:3 gocritic rangeValCopy: each iteration copies 144 bytes (consider pointers or indexing)
plugins/inputs/monit/monit.go:247:2 gocritic rangeValCopy: each iteration copies 504 bytes (consider pointers or indexing)
plugins/inputs/mqtt_consumer/mqtt_consumer.go:137:2 gocritic rangeValCopy: each iteration copies 152 bytes (consider pointers or indexing)
plugins/inputs/mqtt_consumer/mqtt_consumer.go:295:3 gocritic rangeValCopy: each iteration copies 152 bytes (consider pointers or indexing)
plugins/inputs/nginx_plus/nginx_plus.go:399:3 gocritic rangeValCopy: each iteration copies 240 bytes (consider pointers or indexing)
plugins/inputs/nginx_plus/nginx_plus.go:455:2 gocritic rangeValCopy: each iteration copies 176 bytes (consider pointers or indexing)
plugins/inputs/nginx_plus/nginx_plus.go:524:3 gocritic rangeValCopy: each iteration copies 184 bytes (consider pointers or indexing)
plugins/inputs/nginx_plus_api/nginx_plus_api_metrics.go:367:3 gocritic rangeValCopy: each iteration copies 224 bytes (consider pointers or indexing)
plugins/inputs/nginx_plus_api/nginx_plus_api_metrics.go:431:2 gocritic rangeValCopy: each iteration copies 176 bytes (consider pointers or indexing)
plugins/inputs/nginx_plus_api/nginx_plus_api_metrics.go:577:3 gocritic rangeValCopy: each iteration copies 168 bytes (consider pointers or indexing)
plugins/inputs/nginx_sts/nginx_sts.go:232:3 gocritic rangeValCopy: each iteration copies 170 bytes (consider pointers or indexing)
plugins/inputs/nginx_vts/nginx_vts.go:202:2 gocritic rangeValCopy: each iteration copies 136 bytes (consider pointers or indexing)
plugins/inputs/nginx_vts/nginx_vts.go:233:3 gocritic rangeValCopy: each iteration copies 136 bytes (consider pointers or indexing)
plugins/inputs/nsq/nsq.go:214:2 gocritic rangeValCopy: each iteration copies 225 bytes (consider pointers or indexing)
plugins/inputs/nvidia_smi/schema_v11/parser.go:17:2 gocritic rangeValCopy: each iteration copies 656 bytes (consider pointers or indexing)
plugins/inputs/nvidia_smi/schema_v12/parser.go:25:2 gocritic rangeValCopy: each iteration copies 2640 bytes (consider pointers or indexing)
plugins/inputs/nvidia_smi/schema_v12/parser.go:81:3 gocritic rangeValCopy: each iteration copies 192 bytes (consider pointers or indexing)
plugins/inputs/opensearch_query/opensearch_query.go:76:2 gocritic rangeValCopy: each iteration copies 200 bytes (consider pointers or indexing)
plugins/inputs/opensearch_query/opensearch_query.go:142:2 gocritic rangeValCopy: each iteration copies 200 bytes (consider pointers or indexing)
plugins/inputs/openstack/openstack.go:337:2 gocritic rangeValCopy: each iteration copies 176 bytes (consider pointers or indexing)
plugins/inputs/openstack/openstack.go:368:2 gocritic rangeValCopy: each iteration copies 144 bytes (consider pointers or indexing)
plugins/inputs/openstack/openstack.go:398:2 gocritic rangeValCopy: each iteration copies 176 bytes (consider pointers or indexing)
plugins/inputs/openstack/openstack.go:430:2 gocritic rangeValCopy: each iteration copies 320 bytes (consider pointers or indexing)
plugins/inputs/openstack/openstack.go:472:2 gocritic rangeValCopy: each iteration copies 336 bytes (consider pointers or indexing)
plugins/inputs/openstack/openstack.go:517:2 gocritic rangeValCopy: each iteration copies 240 bytes (consider pointers or indexing)
plugins/inputs/openstack/openstack.go:559:2 gocritic rangeValCopy: each iteration copies 208 bytes (consider pointers or indexing)
plugins/inputs/openstack/openstack.go:592:2 gocritic rangeValCopy: each iteration copies 145 bytes (consider pointers or indexing)
plugins/inputs/openstack/openstack.go:627:2 gocritic rangeValCopy: each iteration copies 136 bytes (consider pointers or indexing)
plugins/inputs/openstack/openstack.go:704:2 gocritic rangeValCopy: each iteration copies 328 bytes (consider pointers or indexing)
plugins/inputs/openstack/openstack.go:759:2 gocritic rangeValCopy: each iteration copies 216 bytes (consider pointers or indexing)
plugins/inputs/openstack/openstack.go:778:2 gocritic rangeValCopy: each iteration copies 344 bytes (consider pointers or indexing)
plugins/inputs/openstack/openstack.go:787:3 gocritic rangeValCopy: each iteration copies 400 bytes (consider pointers or indexing)
plugins/inputs/openstack/openstack.go:805:2 gocritic rangeValCopy: each iteration copies 344 bytes (consider pointers or indexing)
plugins/inputs/openweathermap/openweathermap.go:232:2 gocritic rangeValCopy: each iteration copies 200 bytes (consider pointers or indexing)
plugins/inputs/openweathermap/openweathermap.go:289:2 gocritic rangeValCopy: each iteration copies 200 bytes (consider pointers or indexing)
plugins/inputs/proxmox/proxmox.go:125:2 gocritic rangeValCopy: each iteration copies 176 bytes (consider pointers or indexing)
plugins/inputs/rabbitmq/rabbitmq.go:573:2 gocritic rangeValCopy: each iteration copies 344 bytes (consider pointers or indexing)
plugins/inputs/rabbitmq/rabbitmq.go:636:2 gocritic rangeValCopy: each iteration copies 186 bytes (consider pointers or indexing)
plugins/inputs/rabbitmq/rabbitmq.go:672:2 gocritic rangeValCopy: each iteration copies 200 bytes (consider pointers or indexing)
plugins/inputs/riemann_listener/riemann_listener.go:206:3 gocritic rangeValCopy: each iteration copies 144 bytes (consider pointers or indexing)
plugins/inputs/snmp_legacy/snmp_legacy.go:212:2 gocritic rangeValCopy: each iteration copies 232 bytes (consider pointers or indexing)
plugins/inputs/solr/api.go:225:2 gocritic rangeValCopy: each iteration copies 144 bytes (consider pointers or indexing)
plugins/inputs/sql/sql.go:249:2 gocritic rangeValCopy: each iteration copies 432 bytes (consider pointers or indexing)
plugins/inputs/sql/sql.go:409:2 gocritic rangeValCopy: each iteration copies 432 bytes (consider pointers or indexing)
plugins/inputs/sql/sql.go:447:2 gocritic rangeValCopy: each iteration copies 432 bytes (consider pointers or indexing)
plugins/inputs/sql/sql.go:476:2 gocritic rangeValCopy: each iteration copies 432 bytes (consider pointers or indexing)
plugins/inputs/statsd/statsd.go:245:3 gocritic rangeValCopy: each iteration copies 136 bytes (consider pointers or indexing)
plugins/inputs/supervisor/supervisor.go:82:2 gocritic rangeValCopy: each iteration copies 136 bytes (consider pointers or indexing)
plugins/inputs/upsd/upsd.go:211:2 gocritic rangeValCopy: each iteration copies 128 bytes (consider pointers or indexing)
plugins/inputs/vsphere/endpoint.go:648:2 gocritic rangeValCopy: each iteration copies 648 bytes (consider pointers or indexing)
plugins/inputs/vsphere/endpoint.go:670:2 gocritic rangeValCopy: each iteration copies 944 bytes (consider pointers or indexing)
plugins/inputs/vsphere/endpoint.go:719:2 gocritic rangeValCopy: each iteration copies 776 bytes (consider pointers or indexing)
plugins/inputs/vsphere/endpoint.go:748:2 gocritic rangeValCopy: each iteration copies 1416 bytes (consider pointers or indexing)
plugins/inputs/vsphere/endpoint.go:782:2 gocritic rangeValCopy: each iteration copies 2040 bytes (consider pointers or indexing)
plugins/inputs/vsphere/endpoint.go:875:2 gocritic rangeValCopy: each iteration copies 688 bytes (consider pointers or indexing)
plugins/inputs/vsphere/vsan.go:271:4 gocritic rangeValCopy: each iteration copies 144 bytes (consider pointers or indexing)
plugins/inputs/vsphere/vsphere_test.go:258:2 gocritic rangeValCopy: each iteration copies 2040 bytes (consider pointers or indexing)
plugins/inputs/wireguard/wireguard.go:62:3 gocritic rangeValCopy: each iteration copies 152 bytes (consider pointers or indexing)
plugins/inputs/zipkin/convert.go:29:2 gocritic rangeValCopy: each iteration copies 160 bytes (consider pointers or indexing)
plugins/outputs/application_insights/application_insights_test.go:451:2 gocritic rangeValCopy: each iteration copies 176 bytes (consider pointers or indexing)
plugins/parsers/binary/config.go:72:2 gocritic rangeValCopy: each iteration copies 128 bytes (consider pointers or indexing)
plugins/parsers/binary/config.go:147:2 gocritic rangeValCopy: each iteration copies 128 bytes (consider pointers or indexing)
plugins/parsers/json_v2/parser.go:104:2 gocritic rangeValCopy: each iteration copies 160 bytes (consider pointers or indexing)
plugins/parsers/json_v2/parser.go:151:2 gocritic rangeValCopy: each iteration copies 160 bytes (consider pointers or indexing)
plugins/parsers/json_v2/parser.go:454:2 gocritic rangeValCopy: each iteration copies 137 bytes (consider pointers or indexing)
plugins/parsers/json_v2/parser.go:473:2 gocritic rangeValCopy: each iteration copies 216 bytes (consider pointers or indexing)
plugins/parsers/xpath/parser.go:159:2 gocritic rangeValCopy: each iteration copies 304 bytes (consider pointers or indexing)
plugins/parsers/xpath/parser.go:208:2 gocritic rangeValCopy: each iteration copies 304 bytes (consider pointers or indexing)
plugins/processors/regex/regex.go:41:2 gocritic rangeValCopy: each iteration copies 128 bytes (consider pointers or indexing)
plugins/processors/regex/regex.go:50:2 gocritic rangeValCopy: each iteration copies 128 bytes (consider pointers or indexing)
plugins/processors/regex/regex.go:60:2 gocritic rangeValCopy: each iteration copies 128 bytes (consider pointers or indexing)
plugins/processors/regex/regex.go:79:3 gocritic rangeValCopy: each iteration copies 128 bytes (consider pointers or indexing)
plugins/processors/regex/regex.go:83:3 gocritic rangeValCopy: each iteration copies 128 bytes (consider pointers or indexing)
plugins/processors/regex/regex.go:87:3 gocritic rangeValCopy: each iteration copies 128 bytes (consider pointers or indexing)
plugins/processors/regex/regex.go:91:3 gocritic rangeValCopy: each iteration copies 128 bytes (consider pointers or indexing)
plugins/processors/regex/regex.go:95:3 gocritic rangeValCopy: each iteration copies 128 bytes (consider pointers or indexing)
plugins/processors/strings/strings.go:182:2 gocritic rangeValCopy: each iteration copies 208 bytes (consider pointers or indexing)
plugins/processors/strings/strings.go:186:2 gocritic rangeValCopy: each iteration copies 208 bytes (consider pointers or indexing)
plugins/processors/strings/strings.go:190:2 gocritic rangeValCopy: each iteration copies 208 bytes (consider pointers or indexing)
plugins/processors/strings/strings.go:196:2 gocritic rangeValCopy: each iteration copies 208 bytes (consider pointers or indexing)
plugins/processors/strings/strings.go:205:2 gocritic rangeValCopy: each iteration copies 208 bytes (consider pointers or indexing)
plugins/processors/strings/strings.go:214:2 gocritic rangeValCopy: each iteration copies 208 bytes (consider pointers or indexing)
plugins/processors/strings/strings.go:223:2 gocritic rangeValCopy: each iteration copies 208 bytes (consider pointers or indexing)
plugins/processors/strings/strings.go:228:2 gocritic rangeValCopy: each iteration copies 208 bytes (consider pointers or indexing)
plugins/processors/strings/strings.go:233:2 gocritic rangeValCopy: each iteration copies 208 bytes (consider pointers or indexing)
plugins/processors/strings/strings.go:245:2 gocritic rangeValCopy: each iteration copies 208 bytes (consider pointers or indexing)
plugins/processors/strings/strings.go:256:2 gocritic rangeValCopy: each iteration copies 208 bytes (consider pointers or indexing)
plugins/processors/strings/strings.go:270:2 gocritic rangeValCopy: each iteration copies 208 bytes (consider pointers or indexing)
plugins/processors/strings/strings.go:287:3 gocritic rangeValCopy: each iteration copies 208 bytes (consider pointers or indexing)
plugins/secretstores/oauth2/oauth2.go:93:2 gocritic rangeValCopy: each iteration copies 160 bytes (consider pointers or indexing)
Additional configuration
For this checker, additional configuration can be provided:
rangeValCopy:
# Size in bytes that makes the warning trigger.
# Default: 128
sizeThreshold: 32
# Whether to check test functions.
# Default: true
skipTestFuncs: false
Description
This issue starts a discussion about enabling:
Example
Before:
After:
Expected output
Decision about enabling or not enabling this checker.
Findings
For this checker, the following findings were found in the current codebase:
Additional configuration
For this checker, additional configuration can be provided: