Changeset 228237 in webkit


Ignore:
Timestamp:
Feb 7, 2018, 11:33:27 AM (7 years ago)
Author:
Antti Koivisto
Message:

StyleBench: Attribute selectors and other improvements
https://bugs.webkit.org/show_bug.cgi?id=182387

Reviewed by Joseph Pecoraro.

  • Add some attributes to elements in all tests
  • Add some attribute selectors to stylesheets in all tests
  • Also add some * selectors to all stylesheets.
  • Add attribute mutation step to all suites
  • Make test steps do more mutations (25->100) and reduce the number of steps to keep testing time in check. Too fast steps were running into timer resolution limits.
  • StyleBench/resources/style-bench.js:

(defaultConfiguration):
(prototype.randomAttributeName):
(prototype.randomAttributeValue):
(prototype.randomAttributeSelector):
(prototype.makeCompoundSelector):
(prototype.makeElement):
(prototype.addClasses):
(prototype.removeClasses):
(prototype.mutateAttributes):
(prototype.async.runForever):

  • StyleBench/resources/tests.js:

(makeSteps):
(makeSuite):

Location:
trunk/PerformanceTests
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/PerformanceTests/ChangeLog

    r228023 r228237  
     12018-02-01  Antti Koivisto  <antti@apple.com>
     2
     3        StyleBench: Attribute selectors and other improvements
     4        https://bugs.webkit.org/show_bug.cgi?id=182387
     5
     6        Reviewed by Joseph Pecoraro.
     7
     8        - Add some attributes to elements in all tests
     9        - Add some attribute selectors to stylesheets in all tests
     10        - Also add some * selectors to all stylesheets.
     11        - Add attribute mutation step to all suites
     12        - Make test steps do more mutations (25->100) and reduce the number of steps to keep testing time in check.
     13          Too fast steps were running into timer resolution limits.
     14
     15        * StyleBench/resources/style-bench.js:
     16        (defaultConfiguration):
     17        (prototype.randomAttributeName):
     18        (prototype.randomAttributeValue):
     19        (prototype.randomAttributeSelector):
     20        (prototype.makeCompoundSelector):
     21        (prototype.makeElement):
     22        (prototype.addClasses):
     23        (prototype.removeClasses):
     24        (prototype.mutateAttributes):
     25        (prototype.async.runForever):
     26        * StyleBench/resources/tests.js:
     27        (makeSteps):
     28        (makeSuite):
     29
    1302018-02-01  Geoffrey Garen  <ggaren@apple.com>
    231
  • trunk/PerformanceTests/StyleBench/resources/style-bench.js

    r227769 r228237  
    5252            classCount: 200,
    5353            classChance: 0.3,
     54            starChance: 0.05,
     55            attributeChance: 0.02,
     56            attributeCount: 10,
     57            attributeValueCount: 20,
     58            attributeOperators: ['','='],
     59            elementClassChance: 0.5,
     60            elementMaximumClasses: 3,
     61            elementAttributeChance: 0.2,
     62            elementMaximumAttributes: 3,
    5463            combinators: [' ', '>',],
    5564            pseudoClasses: [],
     
    6372            repeatingSequenceChance: 0.2,
    6473            repeatingSequenceMaximumLength: 3,
    65             leafClassMutationChance: 0.1,
     74            leafMutationChance: 0.1,
    6675            styleSeed: 1,
    6776            domSeed: 2,
     77            stepCount: 5,
     78            mutationsPerStep: 100,
    6879        };
    6980    }
     
    177188    }
    178189
     190    randomAttributeName()
     191    {
     192        const attributeCount = this.configuration.attributeCount;
     193        return `attr${ this.random.numberSquareWeightedToLow(attributeCount) }`;
     194    }
     195
     196    randomAttributeValue()
     197    {
     198        const attributeValueCount = this.configuration.attributeValueCount;
     199        const valueNum = this.random.numberSquareWeightedToLow(attributeValueCount);
     200        if (valueNum == 0)
     201            return "";
     202        if (valueNum == 1)
     203            return "val";
     204        return `val${valueNum}`;
     205    }
     206
    179207    randomCombinator()
    180208    {
     
    198226    }
    199227
     228    randomAttributeSelector()
     229    {
     230        const name = this.randomAttributeName();
     231        const operators = this.configuration.attributeOperators;
     232        const operator = operators[this.random.numberSquareWeightedToLow(operators.length)];
     233        if (operator == '')
     234            return `[${name}]`;
     235        const value = this.randomAttributeValue();
     236        return `[${name}${operator}"${value}"]`;
     237    }
     238
    200239    makeCompoundSelector(index, length)
    201240    {
     
    205244        const useId = isFirst && this.random.chance(this.configuration.idChance);
    206245        const useElement = !useId && (usePseudoClass || this.random.chance(this.configuration.elementChance)); // :nth-of-type etc only make sense with element
    207         const useClass = !useId && (!useElement || this.random.chance(this.configuration.classChance));
     246        const useAttribute = !useId && this.random.chance(this.configuration.attributeChance);
     247        const useIdElementOrAttribute = useId || useElement || useAttribute;
     248        const useStar = !useIdElementOrAttribute && !isFirst && this.random.chance(this.configuration.starChance);
     249        const useClass = !useId && !useStar && (!useIdElementOrAttribute || this.random.chance(this.configuration.classChance));
    208250        const useBeforeOrAfter = isLast && this.random.chance(this.configuration.beforeAfterChance);
    209251        let result = "";
    210252        if (useElement)
    211253            result += this.randomElementName();
     254        if (useStar)
     255            result = "*";
    212256        if (useId)
    213257            result += "#" + this.randomId();
     
    219263            }
    220264        }
     265        if (useAttribute)
     266            result += this.randomAttributeSelector();
     267
    221268        if (usePseudoClass)
    222269            result +=  ":" + this.randomPseudoClass(isLast);
     
    283330    {
    284331        const element = document.createElement(this.randomElementName());
    285         const hasClasses = this.random.chance(0.5);
     332        const hasClasses = this.random.chance(this.configuration.elementClassChance);
     333        const hasAttributes = this.random.chance(this.configuration.elementAttributeChance);
    286334        if (hasClasses) {
    287             const count = this.random.numberSquareWeightedToLow(3) + 1;
     335            const count = this.random.numberSquareWeightedToLow(this.configuration.elementMaximumClasses) + 1;
    288336            for (let i = 0; i < count; ++i)
    289337                element.classList.add(this.randomClassName());
     338        }
     339        if (hasAttributes) {
     340            const count = this.random.number(this.configuration.elementMaximumAttributes) + 1;
     341            for (let i = 0; i < count; ++i)
     342                element.setAttribute(this.randomAttributeName(), this.randomAttributeValue());
    290343        }
    291344        const hasId = this.random.chance(this.configuration.idChance);
     
    366419            const element = this.randomTreeElement();
    367420            // There are more leaves than branches. Avoid skewing towards leaf mutations.
    368             if (!element.firstChild && !this.random.chance(this.configuration.leafClassMutationChance))
     421            if (!element.firstChild && !this.random.chance(this.configuration.leafMutationChance))
    369422                continue;
    370423            ++i;
     
    379432            const element = this.randomTreeElement();
    380433            const classList = element.classList;
    381             if (!element.firstChild && !this.random.chance(this.configuration.leafClassMutationChance))
     434            if (!element.firstChild && !this.random.chance(this.configuration.leafMutationChance))
    382435                continue;
    383436            if (!classList.length)
     
    415468        }
    416469        this.updateCachedTestElements();
     470    }
     471
     472    mutateAttributes(count)
     473    {
     474        for (let i = 0; i < count;) {
     475            const element = this.randomTreeElement();
     476            // There are more leaves than branches. Avoid skewing towards leaf mutations.
     477            if (!element.firstChild && !this.random.chance(this.configuration.leafMutationChance))
     478                continue;
     479            const attributeNames = element.getAttributeNames();
     480            let mutatedAttributes = false;
     481            for (const name of attributeNames) {
     482                if (name == "class" || name == "id")
     483                    continue;
     484                if (this.random.chance(0.5))
     485                    element.removeAttribute(name);
     486                else
     487                    element.setAttribute(name, this.randomAttributeValue());
     488                mutatedAttributes = true;
     489            }
     490            if (!mutatedAttributes) {
     491                const attributeCount = this.random.number(this.configuration.elementMaximumAttributes) + 1;
     492                for (let j = 0; j < attributeCount; ++j)
     493                    element.setAttribute(this.randomAttributeName(), this.randomAttributeValue());
     494            }
     495            ++i;
     496        }
    417497    }
    418498
     
    424504            this.addLeafElements(10);
    425505            this.removeLeafElements(10);
     506            this.mutateAttributes(10);
    426507
    427508            await nextAnimationFrame();
  • trunk/PerformanceTests/StyleBench/resources/tests.js

    r227863 r228237  
    1 function makeSteps(count)
     1function makeSteps(configuration)
    22{
    33    const steps = [];
    4     for (i = 0; i < count; ++i) {
     4    for (i = 0; i < configuration.stepCount; ++i) {
    55        steps.push(new BenchmarkTestStep(`Adding classes - ${i}`, (bench, contentWindow, contentDocument) => {
    6             bench.addClasses(25);
     6            bench.addClasses(configuration.mutationsPerStep);
    77        }));
    88        steps.push(new BenchmarkTestStep(`Removing classes - ${i}`, (bench, contentWindow, contentDocument) => {
    9             bench.removeClasses(25);
     9            bench.removeClasses(configuration.mutationsPerStep);
     10        }));
     11        steps.push(new BenchmarkTestStep(`Mutating attributes - ${i}`, (bench, contentWindow, contentDocument) => {
     12            bench.mutateAttributes(configuration.mutationsPerStep);
    1013        }));
    1114        steps.push(new BenchmarkTestStep(`Adding leaf elements - ${i}`, (bench, contentWindow, contentDocument) => {
    12             bench.addLeafElements(25);
     15            bench.addLeafElements(configuration.mutationsPerStep);
    1316        }));
    1417        steps.push(new BenchmarkTestStep(`Removing leaf elements - ${i}`, (bench, contentWindow, contentDocument) => {
    15             bench.removeLeafElements(25);
     18            bench.removeLeafElements(configuration.mutationsPerStep);
    1619        }));
    1720    }
     
    2932            });
    3033        },
    31         tests: makeSteps(10),
     34        tests: makeSteps(configuration),
    3235    };
    3336}
Note: See TracChangeset for help on using the changeset viewer.