Skip to content

Commit 0707a93

Browse files
author
Tim Appelhans
committed
include performance statistics in console output of geoarrowDummyWidget
1 parent e9d5c9d commit 0707a93

File tree

4 files changed

+49
-10
lines changed

4 files changed

+49
-10
lines changed

README.Rmd

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ remotes::install_github("r-spatial/geoarrowWidget")
3737
For testing purposes, `geoarrowWidget` provides a minimal `htmlwidget` called
3838
`geoarrowDummyWidget`. Here's an example of how to use it:
3939

40-
```r
40+
```{r, eval=FALSE}
4141
library(geoarrowWidget)
4242
library(wk)
4343
library(nanoarrow)
@@ -84,9 +84,21 @@ wgt
8484

8585
This will create a web page with the data attached as a geoarrow object.
8686
In the browser console (press F12) this will look something like this
87-
(depending on the browser obviously, Librewolf in this case)
87+
(depending on the browser obviously, Librewolf in this case). You should see two
88+
entries:
89+
90+
1. `Object` - the geoarrow data
91+
2. `PerformanceResourceTiming` - details about the performance of loading the data
92+
including `encodedBodySize` of the data in Bytes and `duration` in milliseconds.
93+
94+
Another way to see how long it takes to load the data is to open the `Network` tab
95+
in the developer tools and refresh the page.
8896

8997
![](man/figures/browser_console.png)
98+
_Note: the 200MB `encodedBodySize` and 375ms `duration` in the screenshot are the
99+
result of running the above code with `1e7` points._
100+
101+
<br>
90102

91103
The page source (press <CTRL + u>) will look something like this, where in
92104
line 11 you see the attached test.arrow file and above the necessary scripts
@@ -96,7 +108,7 @@ line 11 you see the attached test.arrow file and above the necessary scripts
96108

97109
<br>
98110

99-
The general usage pattern is highlighted in [these lines of `geoarrowDummyWidget`](https://github.com/r-spatial/geoarrowWidget/blob/master/inst/htmlwidgets/geoarrowDummyWidget.js#L17-L30)
111+
The general usage pattern is highlighted in [these lines of `geoarrowDummyWidget`](https://github.com/r-spatial/geoarrowWidget/blob/master/inst/htmlwidgets/geoarrowDummyWidget.js#L33-L42)
100112

101113
### Acknowledgment
102114

README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,22 @@ wgt
7474

7575
This will create a web page with the data attached as a geoarrow object.
7676
In the browser console (press F12) this will look something like this
77-
(depending on the browser obviously, Librewolf in this case)
77+
(depending on the browser obviously, Librewolf in this case). You should
78+
see two entries:
7879

79-
![](man/figures/browser_console.png)
80+
1. `Object` - the geoarrow data
81+
2. `PerformanceResourceTiming` - details about the performance of
82+
loading the data including `encodedBodySize` of the data in Bytes
83+
and `duration` in milliseconds.
84+
85+
Another way to see how long it takes to load the data is to open the
86+
`Network` tab in the developer tools and refresh the page.
87+
88+
![](man/figures/browser_console.png) *Note: the 200MB `encodedBodySize`
89+
and 375ms `duration` in the screenshot are the result of running the
90+
above code with `1e7` points.*
91+
92+
<br>
8093

8194
The page source (press \<CTRL + u\>) will look something like this,
8295
where in line 11 you see the attached test.arrow file and above the
@@ -88,7 +101,7 @@ further in JavaScript.
88101
<br>
89102

90103
The general usage pattern is highlighted in [these lines of
91-
`geoarrowDummyWidget`](https://github.com/r-spatial/geoarrowWidget/blob/master/inst/htmlwidgets/geoarrowDummyWidget.js#L17-L30)
104+
`geoarrowDummyWidget`](https://github.com/r-spatial/geoarrowWidget/blob/master/inst/htmlwidgets/geoarrowDummyWidget.js#L33-L42)
92105

93106
### Acknowledgment
94107

inst/htmlwidgets/geoarrowDummyWidget.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,24 @@ HTMLWidgets.widget({
1111

1212
renderValue: function(x) {
1313

14-
// TODO: code to render the widget, e.g.
15-
el.innerText = x.message;
16-
1714
// find data attachment
1815
let data_fl = document.getElementById(x.dataname + "-geoarrowWidget-attachment");
1916

17+
// timings to see how long it will take to fetch
18+
// https://stackoverflow.com/a/66865354
19+
let resourceObserver = new PerformanceObserver( (list) => {
20+
list.getEntries()
21+
// get only the one we're interested in
22+
.filter( ({ name }) => name === data_fl.href )
23+
.forEach( (resource) => {
24+
console.log( resource );
25+
} );
26+
// Disconnect after processing the events.
27+
resourceObserver.disconnect();
28+
} );
29+
// make it a resource observer
30+
resourceObserver.observe( { type: "resource" } );
31+
2032
// fetch and read data, then process as arrow table
2133
fetch(data_fl.href)
2234
.then(result => Arrow.tableFromIPC(result))
@@ -27,7 +39,9 @@ HTMLWidgets.widget({
2739

2840
//debugger;
2941
console.log(arrow_table);
30-
});
42+
})
43+
44+
el.innerText = x.message;
3145

3246
},
3347

man/figures/browser_console.png

360 KB
Loading

0 commit comments

Comments
 (0)