Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Used navigator.hardwareConcurrency to set dynamic DPR per device GPU cores

Steven Tey9518ca1b0a44
diff --git a/components/home/globe.tsx b/components/home/globe.tsx
index 51e44015c6..ea9f05258e 100644
--- a/components/home/globe.tsx
+++ b/components/home/globe.tsx
@@ -12,9 +12,6 @@ interface MarkerProps {
size: number;
}
-// Maybe dynamic based on device type?
-const DPR = 1;
-
export default function Globe({ hostname }: { hostname?: string }) {
const { data: markers } = useSWR<MarkerProps[]>(
`/api/edge/coordinates${hostname ? `?hostname=${hostname}` : ""}`,
@@ -25,6 +22,22 @@ export default function Globe({ hostname }: { hostname?: string }) {
const pointerInteracting = useRef(null);
const pointerInteractionMovement = useRef(0);
+ // Dynamic DPR based on # of GPUs to reduce GPU load for slower devices
+ const [DPR, setDPR] = useState(0.5);
+
+ useEffect(() => {
+ const cores = window.navigator.hardwareConcurrency;
+ if (cores) {
+ if (cores >= 8) {
+ setDPR(1);
+ } else if (cores >= 6) {
+ setDPR(0.8);
+ } else if (cores >= 4) {
+ setDPR(0.65);
+ }
+ }
+ });
+
const [{ r }, api] = useSpring(() => ({
r: 0,
config: {