René's URL Explorer Experiment


Title: perf(core): cache media query matches between device changes by edusperoni · Pull Request #11512 · NativeScript/NativeScript · GitHub

Open Graph Title: perf(core): cache media query matches between device changes by edusperoni · Pull Request #11512 · NativeScript/NativeScript

X Title: perf(core): cache media query matches between device changes by edusperoni · Pull Request #11512 · NativeScript/NativeScript

Description: PR Checklist The PR title follows our guidelines: https://github.com/NativeScript/NativeScript/blob/master/tools/notes/CONTRIBUTING.md#commit-messages. There is an issue for the bug/feature this PR is for. To avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it. You have signed the CLA. All existing tests are passing: https://github.com/NativeScript/NativeScript/blob/master/tools/notes/DevelopmentWorkflow.md#running-unit-tests-application. Tests for the changes are included - https://github.com/NativeScript/NativeScript/blob/master/tools/notes/WritingUnitTests.md. What is the current behavior? Every CSS state change on a view (a class added or removed, a pseudo-class toggled) re-collects selector candidates, and for each @media selector scope in the stylesheet that means calling checkIfMediaQueryMatches. That function reads Screen.mainScreen.widthPixels / heightPixels, the orientation and the system appearance through native getters, and re-parses the media query string with regexes, on every call, before it even looks at which features the query uses. collectCandidates only remembers queries that matched, in an array created fresh per view, so a query that does not match is re-evaluated for every scope that uses it, on every view, on every style pass. A query that uses a feature core does not evaluate at all (for example the @media (color-gamut: p3) blocks that Tailwind 4 and postcss-preset-env emit as fallbacks) is treated the same way: it returns false, so it is never cached, and it is re-checked forever even though it can never become true. In a profile of a screen with ~500 labels whose classes change together, with 52 such media scopes in the stylesheet, ~80% of the main-thread time of each interaction was inside checkIfMediaQueryMatches (native screen/appearance getters plus parseQuery); the actual selector matching was under 2%. What is the new behavior? Two commits: 1. Cache match results between device changes media-query-list: match results are cached per query string. The cache is cleared on the application orientationChanged and systemAppearanceChanged events (the same events MediaQueryList already uses for change notifications), so results stay correct across rotations and dark/light switches. onDeviceChange also clears the cache before re-evaluating the registered lists, so listener order cannot leave a list reading a stale result. css-mediaquery: matchQuery memoizes the parsed form of each query string. parseQuery itself is unchanged and still throws on invalid input, which is never cached. application/helpers-common: toggleApplicationEventListeners now queues listeners requested before the platform installs its handler and replays them in setToggleApplicationEventListenersCallback. This guarantees the cache invalidation hook is registered even when a media query is evaluated before application.ios / application.android finishes loading, and also fixes the pre-existing case where a MediaQueryList created that early never received change events. 2. Drop unevaluable media scopes and read device state lazily css-mediaquery: new isEvaluableMediaQuery(query) returns whether a query parses and uses only features the runtime evaluates (width, height, device-width, device-height, orientation, prefers-color-scheme, with min-/max- prefixes). style-scope: _populateRules skips an @media block (and anything nested in it) when its query is not evaluable, with one trace warning in the MediaQuery category. Such a block could never match, so this changes no rendering; it only stops the block from being re-checked on every style pass. @supports blocks were already dropped this way. media-query-list: checkIfMediaQueryMatches checks evaluability first and returns false for an unevaluable query without touching native state. For evaluable queries the values object uses lazy getters, so a width query no longer reads orientation or appearance, an orientation query no longer resolves the screen, and the screen is resolved once per evaluation (shared by width and device-width) rather than once per feature. Unit tests cover: cache reuse and invalidation on device change, MediaQueryList notifications staying in sync with the cache, the pending-listener replay, isEvaluableMediaQuery accept/reject cases, zero device reads for unevaluable queries, feature-driven reads for evaluable ones, and scope dropping (top-level and nested) in _populateRules. Not covered: a change in Screen.mainScreen metrics that is not accompanied by an orientation or appearance event (an external display connecting, for example). Previously such a change was picked up on the next style pass; now it is picked up on the next orientation or appearance change.

Open Graph Description: PR Checklist The PR title follows our guidelines: https://github.com/NativeScript/NativeScript/blob/master/tools/notes/CONTRIBUTING.md#commit-messages. There is an issue for the bug/feature this...

X Description: PR Checklist The PR title follows our guidelines: https://github.com/NativeScript/NativeScript/blob/master/tools/notes/CONTRIBUTING.md#commit-messages. There is an issue for the bug/feature this...

Opengraph URL: https://github.com/NativeScript/NativeScript/pull/11512

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:5b9b5423-1f19-cc49-4ba1-95dbd02643ca
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idD6E4:10D9F8:17007F8:1E3DCD7:6B01304E
html-safe-nonce54373fc0b689a4170868ede530fe7c4690b762ae39c6cead970e349484ce79d4
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENkU0OjEwRDlGODoxNzAwN0Y4OjFFM0RDRDc6NkIwMTMwNEUiLCJ2aXNpdG9yX2lkIjoiODc2MDkzODM0NzMxODI5MjU1OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacad7c711a71a544480c5b903adc6007ee1f97ad9b64ee10252bf98cfd81de1446
hovercard-subject-tagpull_request:4776694118
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/NativeScript/NativeScript/pull/11512/files
twitter:imagehttps://avatars.githubusercontent.com/u/4061767?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/4061767?s=400&v=4
og:image:altPR Checklist The PR title follows our guidelines: https://github.com/NativeScript/NativeScript/blob/master/tools/notes/CONTRIBUTING.md#commit-messages. There is an issue for the bug/feature this...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/NativeScript/NativeScript git https://github.com/NativeScript/NativeScript.git
octolytics-dimension-user_id7392261
octolytics-dimension-user_loginNativeScript
octolytics-dimension-repository_id31492490
octolytics-dimension-repository_nwoNativeScript/NativeScript
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id31492490
octolytics-dimension-repository_network_root_nwoNativeScript/NativeScript
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/NativeScript/NativeScript/pull/11512/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FNativeScript%2FNativeScript%2Fpull%2F11512%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FNativeScript%2FNativeScript%2Fpull%2F11512%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=NativeScript%2FNativeScript
Reloadhttps://github.com/NativeScript/NativeScript/pull/11512/files
Reloadhttps://github.com/NativeScript/NativeScript/pull/11512/files
Reloadhttps://github.com/NativeScript/NativeScript/pull/11512/files
NativeScripthttps://github.com/NativeScript
NativeScripthttps://github.com/NativeScript/NativeScript
Codehttps://github.com/NativeScript/NativeScript
Issues231 (231)https://github.com/NativeScript/NativeScript/issues
Pull requests107 (107)https://github.com/NativeScript/NativeScript/pulls
Discussionshttps://github.com/NativeScript/NativeScript/discussions
Actionshttps://github.com/NativeScript/NativeScript/actions
Projectshttps://github.com/NativeScript/NativeScript/projects
Wikihttps://github.com/NativeScript/NativeScript/wiki
Security and qualityhttps://github.com/NativeScript/NativeScript/security
Insightshttps://github.com/NativeScript/NativeScript/insights
Sign up for GitHub https://github.com/signup?return_to=%2FNativeScript%2FNativeScript%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2FNativeScript%2FNativeScript%2Fissues%2Fnew%2Fchoose
edusperonihttps://github.com/edusperoni
mainhttps://github.com/NativeScript/NativeScript/tree/main
perf/cache-media-query-matcheshttps://github.com/NativeScript/NativeScript/tree/perf/cache-media-query-matches
Conversation 2 https://github.com/NativeScript/NativeScript/pull/11512
Commits 2 https://github.com/NativeScript/NativeScript/pull/11512/commits
Checks 8 https://github.com/NativeScript/NativeScript/pull/11512/checks
Files changed https://github.com/NativeScript/NativeScript/pull/11512/files
Please reload this pagehttps://github.com/NativeScript/NativeScript/pull/11512/files
perf(core): cache media query matches between device changes https://github.com/NativeScript/NativeScript/pull/11512/files#top
Show all changes 2 commits https://github.com/NativeScript/NativeScript/pull/11512/files
aac6c56 perf(core): cache media query matches between device changes edusperoni Oct 7, 2026 https://github.com/NativeScript/NativeScript/pull/11512/commits/aac6c5692856669bcb1151f6fcbc022c15fb8913
a243425 perf(core): drop unevaluable media scopes and read device state lazily edusperoni Oct 7, 2026 https://github.com/NativeScript/NativeScript/pull/11512/commits/a24342537e51b3fa884e7f734425e7a18558f38c
Clear filters https://github.com/NativeScript/NativeScript/pull/11512/files
Please reload this pagehttps://github.com/NativeScript/NativeScript/pull/11512/files
Please reload this pagehttps://github.com/NativeScript/NativeScript/pull/11512/files
helpers-common.spec.ts https://github.com/NativeScript/NativeScript/pull/11512/files#diff-3f9f739f2a27dc19cc3b8de7991be383bb4f5630d347e3a52ebbe26036039bcc
helpers-common.ts https://github.com/NativeScript/NativeScript/pull/11512/files#diff-da7248870b209ffff3527eb4f284cbbac20d35124a9ba6a6d29ee1a99d76cc62
index.spec.ts https://github.com/NativeScript/NativeScript/pull/11512/files#diff-c19a29abb7a8b93b0f624e3c777bd6c11aef1cc3362a79697bd344ec0d9554f6
index.ts https://github.com/NativeScript/NativeScript/pull/11512/files#diff-627550f17b52d605fc8c1c3ca0fc2632ded7f668dd591c6c709c650374a7573b
index.ts https://github.com/NativeScript/NativeScript/pull/11512/files#diff-1ec7e15bd44f67f6c121c96737065e72441ea93e6753117485a78ba58894c76d
match-cache.spec.ts https://github.com/NativeScript/NativeScript/pull/11512/files#diff-fe80bd26e10861e1fdf45ba21396c7e37ebfadba03c69b9307547c79ac8ece5c
style-scope.spec.ts https://github.com/NativeScript/NativeScript/pull/11512/files#diff-ded9e5e66758a6b317a1babf267254e57df0f2b49ae79dde9932aa2056d2fd44
style-scope.ts https://github.com/NativeScript/NativeScript/pull/11512/files#diff-c9f6d61e7dbc2518a8583def66f2006ffc9759770355a985971ba4657b0e7e30
packages/core/application/helpers-common.spec.tshttps://github.com/NativeScript/NativeScript/pull/11512/files#diff-3f9f739f2a27dc19cc3b8de7991be383bb4f5630d347e3a52ebbe26036039bcc
View file https://github.com/NativeScript/NativeScript/blob/a24342537e51b3fa884e7f734425e7a18558f38c/packages/core/application/helpers-common.spec.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/NativeScript/pull/11512/{{ revealButtonHref }}
packages/core/application/helpers-common.tshttps://github.com/NativeScript/NativeScript/pull/11512/files#diff-da7248870b209ffff3527eb4f284cbbac20d35124a9ba6a6d29ee1a99d76cc62
View file https://github.com/NativeScript/NativeScript/blob/a24342537e51b3fa884e7f734425e7a18558f38c/packages/core/application/helpers-common.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/NativeScript/pull/11512/{{ revealButtonHref }}
https://github.com/NativeScript/NativeScript/pull/11512/files#diff-da7248870b209ffff3527eb4f284cbbac20d35124a9ba6a6d29ee1a99d76cc62
https://github.com/NativeScript/NativeScript/pull/11512/files#diff-da7248870b209ffff3527eb4f284cbbac20d35124a9ba6a6d29ee1a99d76cc62
packages/core/css-mediaquery/index.spec.tshttps://github.com/NativeScript/NativeScript/pull/11512/files#diff-c19a29abb7a8b93b0f624e3c777bd6c11aef1cc3362a79697bd344ec0d9554f6
View file https://github.com/NativeScript/NativeScript/blob/a24342537e51b3fa884e7f734425e7a18558f38c/packages/core/css-mediaquery/index.spec.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/NativeScript/pull/11512/{{ revealButtonHref }}
https://github.com/NativeScript/NativeScript/pull/11512/files#diff-c19a29abb7a8b93b0f624e3c777bd6c11aef1cc3362a79697bd344ec0d9554f6
packages/core/css-mediaquery/index.tshttps://github.com/NativeScript/NativeScript/pull/11512/files#diff-627550f17b52d605fc8c1c3ca0fc2632ded7f668dd591c6c709c650374a7573b
View file https://github.com/NativeScript/NativeScript/blob/a24342537e51b3fa884e7f734425e7a18558f38c/packages/core/css-mediaquery/index.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/NativeScript/pull/11512/{{ revealButtonHref }}
https://github.com/NativeScript/NativeScript/pull/11512/files#diff-627550f17b52d605fc8c1c3ca0fc2632ded7f668dd591c6c709c650374a7573b
https://github.com/NativeScript/NativeScript/pull/11512/files#diff-627550f17b52d605fc8c1c3ca0fc2632ded7f668dd591c6c709c650374a7573b
packages/core/media-query-list/index.tshttps://github.com/NativeScript/NativeScript/pull/11512/files#diff-1ec7e15bd44f67f6c121c96737065e72441ea93e6753117485a78ba58894c76d
View file https://github.com/NativeScript/NativeScript/blob/a24342537e51b3fa884e7f734425e7a18558f38c/packages/core/media-query-list/index.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/NativeScript/pull/11512/{{ revealButtonHref }}
https://github.com/NativeScript/NativeScript/pull/11512/files#diff-1ec7e15bd44f67f6c121c96737065e72441ea93e6753117485a78ba58894c76d
https://github.com/NativeScript/NativeScript/pull/11512/files#diff-1ec7e15bd44f67f6c121c96737065e72441ea93e6753117485a78ba58894c76d
https://github.com/NativeScript/NativeScript/pull/11512/files#diff-1ec7e15bd44f67f6c121c96737065e72441ea93e6753117485a78ba58894c76d
packages/core/media-query-list/match-cache.spec.tshttps://github.com/NativeScript/NativeScript/pull/11512/files#diff-fe80bd26e10861e1fdf45ba21396c7e37ebfadba03c69b9307547c79ac8ece5c
View file https://github.com/NativeScript/NativeScript/blob/a24342537e51b3fa884e7f734425e7a18558f38c/packages/core/media-query-list/match-cache.spec.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/NativeScript/pull/11512/{{ revealButtonHref }}
packages/core/ui/styling/style-scope.spec.tshttps://github.com/NativeScript/NativeScript/pull/11512/files#diff-ded9e5e66758a6b317a1babf267254e57df0f2b49ae79dde9932aa2056d2fd44
View file https://github.com/NativeScript/NativeScript/blob/a24342537e51b3fa884e7f734425e7a18558f38c/packages/core/ui/styling/style-scope.spec.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/NativeScript/pull/11512/{{ revealButtonHref }}
https://github.com/NativeScript/NativeScript/pull/11512/files#diff-ded9e5e66758a6b317a1babf267254e57df0f2b49ae79dde9932aa2056d2fd44
https://github.com/NativeScript/NativeScript/pull/11512/files#diff-ded9e5e66758a6b317a1babf267254e57df0f2b49ae79dde9932aa2056d2fd44
packages/core/ui/styling/style-scope.tshttps://github.com/NativeScript/NativeScript/pull/11512/files#diff-c9f6d61e7dbc2518a8583def66f2006ffc9759770355a985971ba4657b0e7e30
View file https://github.com/NativeScript/NativeScript/blob/a24342537e51b3fa884e7f734425e7a18558f38c/packages/core/ui/styling/style-scope.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/NativeScript/pull/11512/{{ revealButtonHref }}
https://github.com/NativeScript/NativeScript/pull/11512/files#diff-c9f6d61e7dbc2518a8583def66f2006ffc9759770355a985971ba4657b0e7e30
https://github.com/NativeScript/NativeScript/pull/11512/files#diff-c9f6d61e7dbc2518a8583def66f2006ffc9759770355a985971ba4657b0e7e30
https://github.com/NativeScript/NativeScript/pull/11512/files#diff-c9f6d61e7dbc2518a8583def66f2006ffc9759770355a985971ba4657b0e7e30
https://github.com/NativeScript/NativeScript/pull/11512/files#diff-c9f6d61e7dbc2518a8583def66f2006ffc9759770355a985971ba4657b0e7e30
Please reload this pagehttps://github.com/NativeScript/NativeScript/pull/11512/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.