mirror of
https://github.com/grafana/grafana.git
synced 2026-08-14 15:15:03 -05:00
Performance: add preallocation for some slice/map (#57860)
This change preallocates slices and maps where the size of the data is known before the object is created. Co-authored-by: Joe Blubaugh <joe.blubaugh@grafana.com>
This commit is contained in:
co-authored by
Joe Blubaugh
parent
460be70261
commit
4d8287b319
@@ -5,7 +5,6 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
@@ -34,18 +33,21 @@ func NewAlertmanagerConfig(config *NotificationChannelConfig, fn GetDecryptedVal
|
||||
if urlStr == "" {
|
||||
return nil, errors.New("could not find url property in settings")
|
||||
}
|
||||
var urls []*url.URL
|
||||
for _, uS := range strings.Split(urlStr, ",") {
|
||||
|
||||
urlParts := strings.Split(urlStr, ",")
|
||||
urls := make([]*url.URL, 0, len(urlParts))
|
||||
|
||||
for _, uS := range urlParts {
|
||||
uS = strings.TrimSpace(uS)
|
||||
if uS == "" {
|
||||
continue
|
||||
}
|
||||
uS = strings.TrimSuffix(uS, "/") + "/api/v1/alerts"
|
||||
url, err := url.Parse(uS)
|
||||
u, err := url.Parse(uS)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid url property in settings: %w", err)
|
||||
}
|
||||
urls = append(urls, url)
|
||||
urls = append(urls, u)
|
||||
}
|
||||
return &AlertmanagerConfig{
|
||||
NotificationChannelConfig: config,
|
||||
|
||||
@@ -74,7 +74,7 @@ func createDashboardJSON(data *simplejson.Json, lastModified time.Time, cfg *con
|
||||
}
|
||||
|
||||
func mapV0ToDashboardsAsConfig(v0 []*configV0) ([]*config, error) {
|
||||
var r []*config
|
||||
r := make([]*config, 0, len(v0))
|
||||
seen := make(map[string]bool)
|
||||
|
||||
for _, v := range v0 {
|
||||
@@ -101,7 +101,7 @@ func mapV0ToDashboardsAsConfig(v0 []*configV0) ([]*config, error) {
|
||||
}
|
||||
|
||||
func (dc *configV1) mapToDashboardsAsConfig() ([]*config, error) {
|
||||
var r []*config
|
||||
r := make([]*config, 0, len(dc.Providers))
|
||||
seen := make(map[string]bool)
|
||||
|
||||
for _, v := range dc.Providers {
|
||||
|
||||
@@ -212,7 +212,7 @@ func (m *migration) createNotifier(c *notificationChannel) (*PostableGrafanaRece
|
||||
|
||||
// Create one receiver for every unique notification channel.
|
||||
func (m *migration) createReceivers(allChannels []*notificationChannel) (map[uidOrID]*PostableApiReceiver, []*PostableApiReceiver, error) {
|
||||
var receivers []*PostableApiReceiver
|
||||
receivers := make([]*PostableApiReceiver, 0, len(allChannels))
|
||||
receiversMap := make(map[uidOrID]*PostableApiReceiver)
|
||||
|
||||
set := make(map[string]struct{}) // Used to deduplicate sanitized names.
|
||||
|
||||
@@ -146,7 +146,7 @@ func canUpdate(v1, v2 string) bool {
|
||||
}
|
||||
|
||||
func (s *PluginsService) pluginIDsCSV(m map[string]plugins.PluginDTO) string {
|
||||
var ids []string
|
||||
ids := make([]string, 0, len(m))
|
||||
for pluginID := range m {
|
||||
ids = append(ids, pluginID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user