[go: nahoru, domu]

[css-nesting] Create invisible/signaling rules during parsing

This CL emits invisible rules and signaling rules (which were
introduced by CL:5201402 and follow-ups) during parsing,
in order to use-count two situations:

  1. Instead of "shifting up" bare declarations within nested style
     rules, can we generate wrapping rules "in-place"? [1]

     To figure this out, we generate those would-be in-place
     wrapping rules in ConsumeDeclarationList, except they are
     marked as *invisible*, i.e. they participate until
     the StyleCascade, but are dropped during that process.
     In addition, those invisible rules are marked as *signaling*,
     which means that they trigger a use counter if they have
     some effect on the cascade.

     The hope is that by adding these rules, and proving that
     they don't have any effect, we can conclude that the change
     is safe, because adding the invisible rules gave us the same
     end result as before.

  2. Can we change the effective specificity of the generated
     &-rule wrappers? [2]

     This is only relevant for nested grouping rules, like @media.
     To measure if this is safe, we generate an additional invisible
     wrapping rule (before the regular &-rule) with the new
     specificity characteristics (in ConsumeRuleListOrNested-
     DeclarationList). Additionally, we make the existing &-rule
     signaling. Hopefully, we if we can show that the &-rule
     has no effect on the end result if the (invisible) alternative
     rule is present, we can conclude that it's safe to remove.

The two approaches in (1) and (2) kind of mirror each other:

 - In (1), we add an invisible rule *after* the main rule,
   hoping that the quiet rule has no effect.
 - In (2), we add an invisible rule *before* the main rule,
   hoping that the *main rule* has no effect.

Note that invisible/signaling rules are only emitted when parsing
bare declarations: the rule *parsed* by a call to insertRule
can contain invisible/signaling rules, but nothing special happens
for the insertion itself. In other words, inserting a rule with
CSSOM does not create invisible/signaling sibling rules.

Introducing signaling/invisible rules adds quite a bit of complexity
to the code, and negatively impacts performance. All code introduced
by CL:5201402 and its follow-ups are therefore planned to be removed
again some time during 2024.

StyleCalcPerfTest for this CL:

Initial style (µs)     Before     After    Perf      95% CI (BCa)
=================== ========= ========= ======= =================
ECommerce                8099      8174   -0.9%  [ -1.3%,  -0.6%]
Encyclopedia            72995     73268   -0.4%  [ -0.7%,  -0.0%]
Extension               84010     84599   -0.7%  [ -1.1%,  -0.3%]
News                    33645     33942   -0.9%  [ -1.3%,  -0.5%]
Search                  10059     10133   -0.7%  [ -1.1%,  -0.3%]
Social1                 18862     19007   -0.8%  [ -1.1%,  -0.5%]
Social2                 12782     12885   -0.8%  [ -1.3%,  -0.4%]
Sports                  41048     41146   -0.2%  [ -0.5%,  +0.0%]
Video                   25840     25953   -0.4%  [ -0.6%,  -0.2%]
Geometric mean                            -0.6%  [ -0.9%,  -0.4%]

Parse (µs)             Before     After    Perf      95% CI (BCa)
=================== ========= ========= ======= =================
ECommerce                1401      1435   -2.4%  [ -3.0%,  -1.9%]
Encyclopedia             7794      7935   -1.8%  [ -2.1%,  -1.5%]
Extension                1374      1391   -1.2%  [ -1.5%,  -0.8%]
News                     8372      8579   -2.4%  [ -2.7%,  -2.1%]
Search                   5244      5374   -2.4%  [ -2.8%,  -2.1%]
Social1                 15499     15935   -2.7%  [ -3.2%,  -2.4%]
Social2                   635       653   -2.7%  [ -3.2%,  -2.3%]
Sports                  59797     61250   -2.4%  [ -2.7%,  -2.1%]
Video                   37212     38083   -2.3%  [ -2.6%,  -2.0%]
Geometric mean                            -2.3%  [ -2.5%,  -2.0%]

Recalc style (µs)      Before     After    Perf      95% CI (BCa)
=================== ========= ========= ======= =================
ECommerce                4274      4330   -1.3%  [ -1.7%,  -0.8%]
Encyclopedia            53741     54462   -1.3%  [ -1.8%,  -0.9%]
Extension               67906     69119   -1.8%  [ -2.3%,  -1.3%]
News                    24823     25113   -1.2%  [ -1.8%,  -0.6%]
Search                   4307      4343   -0.8%  [ -1.3%,  -0.3%]
Social1                 10078     10195   -1.2%  [ -1.5%,  -0.8%]
Social2                  7881      7965   -1.1%  [ -1.6%,  -0.6%]
Sports                  18426     18608   -1.0%  [ -1.5%,  -0.6%]
Video                   11884     12000   -1.0%  [ -1.2%,  -0.7%]
Geometric mean                            -1.2%  [ -1.4%,  -0.9%]

Bug: 1517290

[1] https://github.com/w3c/csswg-drafts/issues/8738
[2] https://github.com/w3c/csswg-drafts/issues/9492

Change-Id: Icb12186f02f4c17070f9ef34907136a6d56e7745
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5217094
Reviewed-by: Steinar H Gunderson <sesse@chromium.org>
Commit-Queue: Anders Hartvoll Ruud <andruud@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1255444}
5 files changed
tree: 1019a986b3f95d7a2348eb05f67b11d91c028224
  1. android_webview/
  2. apps/
  3. ash/
  4. base/
  5. build/
  6. build_overrides/
  7. buildtools/
  8. cc/
  9. chrome/
  10. chromecast/
  11. chromeos/
  12. codelabs/
  13. components/
  14. content/
  15. courgette/
  16. crypto/
  17. dbus/
  18. device/
  19. docs/
  20. extensions/
  21. fuchsia_web/
  22. gin/
  23. google_apis/
  24. google_update/
  25. gpu/
  26. headless/
  27. infra/
  28. ios/
  29. ipc/
  30. media/
  31. mojo/
  32. native_client_sdk/
  33. net/
  34. pdf/
  35. ppapi/
  36. printing/
  37. remoting/
  38. rlz/
  39. sandbox/
  40. services/
  41. skia/
  42. sql/
  43. storage/
  44. styleguide/
  45. testing/
  46. third_party/
  47. tools/
  48. ui/
  49. url/
  50. webkit/
  51. .clang-format
  52. .clang-tidy
  53. .clangd
  54. .eslintrc.js
  55. .git-blame-ignore-revs
  56. .gitallowed
  57. .gitattributes
  58. .gitignore
  59. .gitmodules
  60. .gn
  61. .mailmap
  62. .rustfmt.toml
  63. .vpython3
  64. .yapfignore
  65. ATL_OWNERS
  66. AUTHORS
  67. BUILD.gn
  68. CODE_OF_CONDUCT.md
  69. codereview.settings
  70. DEPS
  71. DIR_METADATA
  72. LICENSE
  73. LICENSE.chromium_os
  74. OWNERS
  75. PRESUBMIT.py
  76. PRESUBMIT_test.py
  77. PRESUBMIT_test_mocks.py
  78. README.md
  79. WATCHLISTS
README.md

Logo Chromium

Chromium is an open-source browser project that aims to build a safer, faster, and more stable way for all users to experience the web.

The project's web site is https://www.chromium.org.

To check out the source code locally, don't use git clone! Instead, follow the instructions on how to get the code.

Documentation in the source is rooted in docs/README.md.

Learn how to Get Around the Chromium Source Code Directory Structure.

For historical reasons, there are some small top level directories. Now the guidance is that new top level directories are for product (e.g. Chrome, Android WebView, Ash). Even if these products have multiple executables, the code should be in subdirectories of the product.

If you found a bug, please file it at https://crbug.com/new.