Skip to content

[Bug]: mergeRules OOMs with 20k adjacent equal rules #1747

@Goodwine

Description

@Goodwine

Describe the bug

We recently encountered a memory exhaustion issue during CSS optimization of a large generated CSS file. The root cause appears to be that mergeRules has O(n²) performance and there are several duplicate streams of work (e.g. mapping the same data twice) for max() and min().

Expected behaviour

Compiles OK

Steps to reproduce

scss
@for $i from 1 through 20000 {
  .foo-#{$i} {
    color: red;
  }
}

Version

7.0.5

Preset

default

Environment

OS: Linux 6.16 Debian GNU/Linux
CPU: (16) x64 Intel(R) Xeon(R) CPU @ 2.00GHz
Memory: 93.77 GB / 102.17 GB
Container: Yes
Shell: 5.9 - /usr/bin/zsh

Package details

irrelevant

Additional context

Although it is possible to fix the problem by increasing memory, there are some low hanging fruit in the implementation that I'd like to contribute a fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions