Rostislav Melkumyan's Avatar

Rostislav Melkumyan

@rosti.no

Breaking stuff at @sanity.io

54
Followers
88
Following
20
Posts
02.11.2024
Joined
Posts Following

Latest posts by Rostislav Melkumyan @rosti.no

Preview
Faster Canvas Pixel Manipulation with Typed Arrays – Mozilla Hacks - the Web developer blog Edit: See the section about Endiannes. Typed Arrays can significantly increase the pixel manipulation performance of your HTML5 2D canvas Web apps. This is of particular importance to developers ...

references for the curious:

Uint32Array trick from 2011, still holds up:
hacks.mozilla.org/2011/12/faster-canvas-pixel-manipulation-with-typed-arrays/

canvas reuse patterns:
web.dev/articles/canvas-performance

willReadFrequently for getImageData:
schiener.io/2024-08-02/canvas-willreadfrequently

07.02.2026 16:13 πŸ‘ 5 πŸ” 0 πŸ’¬ 0 πŸ“Œ 0
for (let i = 0; i < pixelCount; i++) {
  const pixel = data32[i]!;

  // unpack RGBA from Uint32Array (little-endian)
  const a = pixel >>> 24;
  if (a <= contrastThreshold) continue;

  const r = pixel & 0xff;
  const g = (pixel >>> 8) & 0xff;
  const b = (pixel >>> 16) & 0xff;

  // squared euclidean distance from white
  const distSq = (r - 255) ** 2 + (g - 255) ** 2 + (b - 255) ** 2;
  if (distSq < contrastDistanceSq) continue;

  // recover x,y from flat index
  const x = i % sw;
  const y = (i - x) / sw;

  // accumulate weighted visual center
  totalWeight += distSq * a;
  weightedX += (x + 0.5) * distSq * a;
  weightedY += (y + 0.5) * distSq * a;

for (let i = 0; i < pixelCount; i++) { const pixel = data32[i]!; // unpack RGBA from Uint32Array (little-endian) const a = pixel >>> 24; if (a <= contrastThreshold) continue; const r = pixel & 0xff; const g = (pixel >>> 8) & 0xff; const b = (pixel >>> 16) & 0xff; // squared euclidean distance from white const distSq = (r - 255) ** 2 + (g - 255) ** 2 + (b - 255) ** 2; if (distSq < contrastDistanceSq) continue; // recover x,y from flat index const x = i % sw; const y = (i - x) / sw; // accumulate weighted visual center totalWeight += distSq * a; weightedX += (x + 0.5) * distSq * a; weightedY += (y + 0.5) * distSq * a;

i collapsed it into 1 pass over a Uint32Array, downsampled to ~45x45, reused canvases at module level, and added caching so changing baseSize/scaleFactor doesn’t re-scan

content detection: 1.4ms -> 37us per logo (38x)
full mount: 29ms -> 828us for 20 logos (35x)

github.com/sanity-labs/...

07.02.2026 16:04 πŸ‘ 2 πŸ” 0 πŸ’¬ 1 πŸ“Œ 0

it was doing 3 full pixel scans per logo (bbox, visual center, density). each scan made a new canvas, drew full-res, then walked every pixel. 400x400 is 160k pixels, 3x

07.02.2026 16:04 πŸ‘ 2 πŸ” 0 πŸ’¬ 1 πŸ“Œ 0

got asked why react-logo-soup doesn’t just precompute visual weights server-side. fair 🧡

07.02.2026 16:04 πŸ‘ 4 πŸ” 0 πŸ’¬ 1 πŸ“Œ 1
Post image

fun css tip from yesterday's react-logo-soup post:

if you render logos as inline-block, the browser treats them like words. which means css text-wrap: balance just works. it distributes logos evenly across lines instead of leaving one sad orphan on the last row

06.02.2026 15:27 πŸ‘ 6 πŸ” 1 πŸ’¬ 0 πŸ“Œ 0

Hey! I wrote something πŸ–ΌοΈ Give it a read!

05.02.2026 18:54 πŸ‘ 4 πŸ” 1 πŸ’¬ 0 πŸ“Œ 0
Code block with the following code:
```groq
export const headingsProjection = \`
  _key,
  "title": array::join(children[].text, ""),
  "level": select(
    style == "h2" => 2,
    style == "h3" => 3
  )
\`
```

Code block with the following code: ```groq export const headingsProjection = \` _key, "title": array::join(children[].text, ""), "level": select( style == "h2" => 2, style == "h3" => 3 ) \` ```

i love groq sm <3

06.05.2025 09:43 πŸ‘ 2 πŸ” 0 πŸ’¬ 0 πŸ“Œ 0

@zed.dev can i get access to your agent beta to test this out in Zed?

11.04.2025 08:41 πŸ‘ 0 πŸ” 0 πŸ’¬ 0 πŸ“Œ 0
Preview
GitHub - sanity-io/sanity-mcp-server: Sanity MCP Server Sanity MCP Server. Contribute to sanity-io/sanity-mcp-server development by creating an account on GitHub.

been hearing that MCP's are the cool new thing - we got one github.com/sanity-io/sa... @sanity.io

10.04.2025 18:17 πŸ‘ 2 πŸ” 0 πŸ’¬ 1 πŸ“Œ 0

Here it is in real-time (and Dark Mode) πŸ₯° Coming to a @sanity.io UI near you πŸ”œ

28.02.2025 14:47 πŸ‘ 7 πŸ” 3 πŸ’¬ 2 πŸ“Œ 0
A Git commit message with the text "feat: remove next/image usage"

A Git commit message with the text "feat: remove next/image usage"

how to become a millionaire

25.02.2025 09:56 πŸ‘ 0 πŸ” 0 πŸ’¬ 0 πŸ“Œ 0

Zed is beyond goated

08.02.2025 11:14 πŸ‘ 0 πŸ” 0 πŸ’¬ 0 πŸ“Œ 0
npm create sanity@latest -- --template nuotsu/sanitypress

npm create sanity@latest -- --template nuotsu/sanitypress

Install SanityPress with the Sanity CLI!

23.01.2025 05:09 πŸ‘ 7 πŸ” 2 πŸ’¬ 1 πŸ“Œ 0

Beautiful!! 🫢

11.01.2025 20:57 πŸ‘ 1 πŸ” 0 πŸ’¬ 0 πŸ“Œ 0
Post image
02.01.2025 08:29 πŸ‘ 2 πŸ” 0 πŸ’¬ 0 πŸ“Œ 0
Video thumbnail

You can now init a new Sanity project with a remote template!

Here are some to get you started:

$ npm create sanity@latest -- --template
sanity-io/sanity-template-astro-clean
sanity-io/sanity-template-nextjs-clean
sanity-io/sanity-template-sveltekit-clean
sanity-io/sanity-template-remix-clean

19.12.2024 18:01 πŸ‘ 20 πŸ” 9 πŸ’¬ 0 πŸ“Œ 1
Video thumbnail

Really impressed by this stack!

Real-time live previews with localized path namesβ€”so cool that this works seamlessly.

@nextjs.org
@sanity.io

next-intl next-intl-docs.vercel.app

10.12.2024 11:03 πŸ‘ 5 πŸ” 3 πŸ’¬ 1 πŸ“Œ 0
Video thumbnail

Bibbidi-Bobbidi-Boo

06.12.2024 09:32 πŸ‘ 1 πŸ” 0 πŸ’¬ 0 πŸ“Œ 0

My theory is that Black Week was invented by SREs to load balance human spendingβ€”turns out spreading chaos across the week is more efficient than handling a single peak day

29.11.2024 12:09 πŸ‘ 3 πŸ” 0 πŸ’¬ 0 πŸ“Œ 0
Post image

idk if arc will even get new features anymore, but a @vercel.com integration is all i want for xmas

27.11.2024 14:10 πŸ‘ 0 πŸ” 0 πŸ’¬ 0 πŸ“Œ 0
Post image

@hamburger.cloud you are in my thoughts every day as I leave the office.

22.11.2024 16:24 πŸ‘ 2 πŸ” 1 πŸ’¬ 2 πŸ“Œ 0
Post image

These are just bad code ligatures tho. Fira's is better imo

16.11.2024 12:28 πŸ‘ 0 πŸ” 0 πŸ’¬ 1 πŸ“Œ 0

❀️❀️❀️

12.11.2024 17:47 πŸ‘ 3 πŸ” 0 πŸ’¬ 0 πŸ“Œ 0

Help us ship more quality bugs 🫢

11.11.2024 15:13 πŸ‘ 2 πŸ” 0 πŸ’¬ 0 πŸ“Œ 0