The SLM retention clean up task `SnapshotRetentionTask` lists all snapshots in order to identify the snapshots to retain and the snapshots to delete. While doing so it retrieves the full snapshot information, including shard snapshot details and shard snapshot failures, to later  only use snapshot metadata and snapshot timestamp to select the snapshots to retain. When the snapshots contain thousands of shards it represents of lot of objects that are unnecessary created, putting a lot of pressure on the garbage collector.

We should improve the way SLM retrieves snapshots to reduce the huge allocations of objects. David made some [interesting](https://github.com/elastic/elasticsearch/issues/99953#issuecomment-1738534389) [suggestions](https://github.com/elastic/elasticsearch/issues/99953#issuecomment-1738626743) in comments.

- #100044
- #100053
- #100054
- #100058
- #100065
- #100070
- #100092
x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/slm/SnapshotRetentionConfiguration.java
+ this.minimumSnapshotCount
                    + " cannot be larger than maximum snapshot count "
                    + this.maximumSnapshotCount
            );
        }
    }
    public static SnapshotRetentionConfiguration parse(XContentParser parser, String name) {
        return PARSER.apply(parser, null);
    }
    public TimeValue getExpireAfter() {
        return this.expireAfter;
    }
    public Integer getMinimumSnapshotCount() {
        return this.minimumSnapshotCount;
    }
    public Integer getMaximumSnapshotCount() {
        return this.maximumSnapshotCount;
    }
    /**
     * Return a predicate by which a SnapshotInfo can be tested to see
     * whether it should be deleted according to this retention policy.
     * @param allSnapshots a list of all snapshot pertaining to this SLM policy and repository
     */
    public Predicate<SnapshotInfo> getSnapshotDeletionPredicate(final List<SnapshotInfo> allSnapshots) {
        final int totalSnapshotCount = allSnapshots.size();
        final List<SnapshotInfo> sortedSnapshots = allSnapshots.stream().sorted(Comparator.comparingLong(SnapshotInfo::startTime)).toList();
        int successCount = 0;
        long latestSuccessfulTimestamp = Long.MIN_VALUE;
        for (SnapshotInfo snapshot : allSnapshots) {
            if (snapshot.state() == SnapshotState.SUCCESS) {