firefox-devtools / profiler

Firefox Profiler — Web app for Firefox performance analysis
https://profiler.firefox.com
Mozilla Public License 2.0
1.19k stars 388 forks source link

Use country level grid intensity to calculate CO2e values in power profiles #4479

Open fershad opened 1 year ago

fershad commented 1 year ago

Currently, the CO2e value that is shown in the power profile tooltip is calculated using a global average grid intensity figure.

  _computeCO2eFromPower(power: number): number {
    // total energy Wh to kWh
    const energy = power / 1000;
    const { WORLD } = averageIntensity.data;
    return energy * WORLD;
  }

https://github.com/firefox-devtools/profiler/blob/main/src/components/tooltip/TrackPower.js#L68-L73

This is a good start, but ideally we would be able to generate a value that is more representative of an individual profile. One way to do this would be to use grid intensity of the country in which the profile was captured. For example, if I record a power profile on my laptop in Taiwan, then the CO2e calculation would use Taiwan's annual average grid intensity. CO2.js (which is already used to get the global average grid intensity value) already has average annual grid intensity data for a number of countries.

To do this, we would need a way to know the country in which a profile was recorded. There are privacy concerns around having this information in a profile, which julienw raised in https://github.com/firefox-devtools/profiler/pull/4243#issuecomment-1266624528v.

One possible solution for this would be to keep the country data in the original profile, however if that profile is then shared the user is presented with the option to keep the original location data, or replace it with the global average in the shared profile.

This issue provides a space to talk through the concerns about including such a feature, and other possible concerns/solutions.

┆Issue is synchronized with this Jira Task

fershad commented 1 year ago

@julienw @fqueze any thoughts on taking the carbon emissions estimates a step further?

fqueze commented 1 year ago

@julienw @fqueze any thoughts on taking the carbon emissions estimates a step further?

Yes, I thought some more about this topic, and I think it's important to think about the use cases to design a solution.

If we are thinking about a web developer power profiling their website, it makes sense to use the global average, as the web site will potentially be used anywhere in the world.

The case I can think of where using a more specific value makes a lot of sense is when power profiling in a specific context where the carbon intensity of the actual electricity provider is known. Eg. if someone is working on improving the sustainability of the intranet applications of an organization, it should be possible to use the carbon intensity of the electricity from the organization's provider (that may be from 100% renewable sources when the average energy from the country's grid would not be). To support this use case, I think we need to offer a way to set the actual intensity, rather than specifying the user's country. I opened PR #4672 as a first step in that direction, and explained what the next steps could be.

If we are putting ourselves in the context of a specific user being curious about the carbon footprint of their own browsing, it's likely that they know which electricity provider their home uses, and can find the carbon intensity of that provider (which also won't match the country average).

fershad commented 1 year ago

@fqueze thank you for this. Sorry about the late reply, I was on holidays.

I like the approach you're taking here, and it's great to see some foundations already set in #4672. I do like your idea for iterative next steps as well. Sounds like a good way forwards.

If we want to go one step further towards fixing https://github.com/firefox-devtools/profiler/issues/4479, I think the next step would be to have a preference in Firefox that could be set using about:config to customize the carbon intensity in Firefox, and have it included in all captured power profiles.

And a last step could be to allow setting this preference from an input field in about:profiling. I think each of these steps provides an incremental improvement and they could be done separately.

jgraham commented 1 year ago

If we are thinking about a web developer power profiling their website, it makes sense to use the global average, as the web site will potentially be used anywhere in the world.

This doesn't seem right. Most websites don't get users from a uniform sample of the global population. For example if I'm writing a website providing government information in the UK then most visitors will be from the UK. If I'm writing a website providing public transport information across the EU then most visitors will be from EU countries, even though there will be some representation from the rest of the world (e.g. tourists pre-planning trips).

So really making the numbers accurate for the site in question would require the ability to set custom weights for the contribution of different countries to the userbase, extracted from external data sources like server logs.