Skip to content

Performance Issue in EnvironmentController.convertToProperties #2245

@lc77254

Description

@lc77254

Describe the bug
There is a performance issue for array properties here. The time complexity would be O(N^2) so if we have 1,000 array properties then it would have 1,000,000 circulation.

		for (PropertySource source : sources) {

			@SuppressWarnings("unchecked")
			Map<String, Object> value = (Map<String, Object>) source.getSource();
			for (String key : value.keySet()) {

				if (!key.contains("[")) {

					// Not an array, add unique key to the map
					combinedMap.put(key, value.get(key));

				}
				else {

					// An existing array might have already been added to the property map
					// of an unequal size to the current array. Replace the array key in
					// the current map.
					key = key.substring(0, key.indexOf("["));
					Map<String, Object> filtered = new LinkedHashMap<>();
					for (String index : value.keySet()) {
						if (index.startsWith(key + "[")) {
							filtered.put(index, value.get(index));
						}
					}
					map.put(key, filtered);
				}
			}

		}

Sample
Assuming we have array properties as below.

a[0]: 0
a[1]: 1
...
a[1000]: 1000

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions