Skip to content

Commit

Permalink
add new "Benchmarks" pane in dashboard
Browse files Browse the repository at this point in the history
Purpose is strictly for development purpose. The new pane can
be enabled by setting the advanced setting `benchmarkingPane`
to  `true`.
  • Loading branch information
gorhill committed Nov 2, 2018
1 parent 649f82f commit d693d4f
Show file tree
Hide file tree
Showing 8 changed files with 265 additions and 2 deletions.
30 changes: 30 additions & 0 deletions src/benchmarks.html
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>uBlock — Benchmarks</title>

<link rel="stylesheet" href="css/common.css">
<link rel="stylesheet" href="css/dashboard-common.css">
</head>

<body>

<div class="body">
<p>The purpose of this pane is strictly for development purpose. Please, do <strong>not</strong> open issues about it.</p>
<div id="staticNetFilteringEngine">
<p>Static Network Filtering Engine: <button type="button">Measure</button> <span class="results">?</span></p>
</div>
</div>

<script src="js/vapi.js"></script>
<script src="js/vapi-common.js"></script>
<script src="js/vapi-client.js"></script>
<script src="js/udom.js"></script>
<script src="js/i18n.js"></script>
<script src="js/dashboard-common.js"></script>
<script src="js/benchmarks.js"></script>

</body>
</html>
3 changes: 3 additions & 0 deletions src/css/dashboard.css
Expand Up @@ -76,6 +76,9 @@ iframe {
body:not(.canUpdateShortcuts) .tabButton[href="#shortcuts.html"] {
display: none;
}
body:not(.canBenchmark) .tabButton[href="#benchmarks.html"] {
display: none;
}

@media (max-width: 640px) {
#dashboard-nav {
Expand Down
3 changes: 2 additions & 1 deletion src/dashboard.html
Expand Up @@ -19,7 +19,8 @@
--><a class="tabButton" href="#dyna-rules.html" data-i18n="rulesPageName"></a><!--
--><a class="tabButton" href="#whitelist.html" data-i18n="whitelistPageName"></a><!--
--><a class="tabButton" href="#shortcuts.html" data-i18n="shortcutsPageName"></a><!--
--><a class="tabButton" href="#about.html" data-i18n="aboutPageName"></a>
--><a class="tabButton" href="#about.html" data-i18n="aboutPageName"></a><!--
--><a class="tabButton" href="#benchmarks.html">Benchmarks</a>
</div>
</div>

Expand Down
1 change: 1 addition & 0 deletions src/js/background.js
Expand Up @@ -42,6 +42,7 @@ var µBlock = (function() { // jshint ignore:line
assetFetchTimeout: 30,
autoUpdateAssetFetchPeriod: 120,
autoUpdatePeriod: 7,
benchmarkingPane: false,
cacheStorageCompression: true,
debugScriptlets: false,
cacheControlForFirefox1376932: 'no-cache, no-store, must-revalidate',
Expand Down
204 changes: 204 additions & 0 deletions src/js/benchmarks.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/js/dashboard.js
Expand Up @@ -74,6 +74,10 @@ vAPI.messaging.send('dashboard', { what: 'canUpdateShortcuts' }, response => {
document.body.classList.toggle('canUpdateShortcuts', response === true);
});

vAPI.messaging.send('dashboard', { what: 'benchmarkingPane' }, response => {
document.body.classList.toggle('canBenchmark', response === true);
});

resizeFrame();
window.addEventListener('resize', resizeFrame);
uDom('.tabButton').on('click', onTabClickHandler);
Expand Down
10 changes: 9 additions & 1 deletion src/js/messaging.js
Expand Up @@ -743,7 +743,7 @@ vAPI.messaging.listen('cloudWidget', onMessage);

/******************************************************************************/

var µb = µBlock;
const µb = µBlock;

/******************************************************************************/

Expand Down Expand Up @@ -1039,6 +1039,14 @@ var onMessage = function(request, sender, callback) {
var response;

switch ( request.what ) {
case 'benchmark':
response = µb.staticNetFilteringEngine.benchmark(request.contexts);
break;

case 'benchmarkingPane':
response = µb.hiddenSettings.benchmarkingPane;
break;

case 'canUpdateShortcuts':
response = µb.canUpdateShortcuts;
break;
Expand Down
12 changes: 12 additions & 0 deletions src/js/static-net-filtering.js
Expand Up @@ -2714,6 +2714,18 @@ FilterContainer.prototype.getFilterCount = function() {

/******************************************************************************/

FilterContainer.prototype.benchmark = function(contexts) {
const t0 = performance.now();
const results = [];
for ( const context of contexts ) {
results.push(this.matchString(context));
}
const t1 = performance.now();
return { t0, t1, duration: t1 - t0, results };
};

/******************************************************************************/

return new FilterContainer();

/******************************************************************************/
Expand Down

0 comments on commit d693d4f

Please sign in to comment.