惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The Last Watchdog
The Last Watchdog
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LINUX DO - 热门话题
G
GRAHAM CLULEY
S
Schneier on Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
S
SegmentFault 最新的问题
IT之家
IT之家
阮一峰的网络日志
阮一峰的网络日志
Recorded Future
Recorded Future
I
Intezer
云风的 BLOG
云风的 BLOG
博客园 - Franky
月光博客
月光博客
大猫的无限游戏
大猫的无限游戏
T
Tenable Blog
The Hacker News
The Hacker News
T
The Blog of Author Tim Ferriss
Attack and Defense Labs
Attack and Defense Labs
D
DataBreaches.Net
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
N
News and Events Feed by Topic
有赞技术团队
有赞技术团队
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
N
News and Events Feed by Topic
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
S
Secure Thoughts
The Register - Security
The Register - Security
B
Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
The Cloudflare Blog
Webroot Blog
Webroot Blog
W
WeLiveSecurity
H
Heimdal Security Blog
博客园 - 三生石上(FineUI控件)
V
Vulnerabilities – Threatpost
G
Google Developers Blog
O
OpenAI News
V
V2EX
罗磊的独立博客
博客园_首页
N
News | PayPal Newsroom
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
TaoSecurity Blog
TaoSecurity Blog
Cloudbric
Cloudbric
H
Hacker News: Front Page
博客园 - 叶小钗
T
Tor Project blog
AI
AI

Inside Nutrient

A guide to the invisible work behind documents Introducing Nutrient Documents for Salesforce: Native document generation and signing Document AI vs. traditional OCR: Choosing between OCR, AI, and hybrid pipelines PDF SDK compliance and security evaluation checklist for enterprise teams (2026) Invariant Corp replaces paper processes with Nutrient Workflow and scales without limits What is process mapping? A complete guide Nutrient vs. Conga Composer for Salesforce document generation (2026) Document routing: How to automate document distribution The CTO’s AI playbook: Why accountability architecture beats orchestration Compliance workflow automation: Why built-in compliance is table stakes Workflow diagrams: Examples, symbols, and how to build one that actually runs Digital forms: Replace paper forms with automated workflows Approval workflow software: How to automate approvals Why document-centric automation is different The CEO’s AI playbook: Why decision architecture beats model selection Nutrient SDK product updates for Q1 2026 PDF redaction verification: How to prove sensitive data is permanently removed What is a VPAT? The complete guide to accessibility conformance reports What is PDF/UA? The accessible PDF standard explained Salesforce eSignatures: Generate, sign, and track documents in one flow Online document viewer: Options, tradeoffs, and how to embed one Document viewer for web apps: React, Vue, Angular (2026) Best document viewers in 2026: A buyer’s guide How to edit a PDF in Python: Add text, images, and annotations Nutrient advances Workflow platform with agentic AI for enterprise-grade speed and consistency in document-heavy operations How to create a Salesforce quote template from opportunity data The business case for accessibility: Five ways it drives enterprise value Python PDF library comparison (2026): 7 libraries for developers Why your AI agent hallucinates PDF table data PDF.js limitations: When to upgrade to a commercial PDF SDK How Subject scaled 5× with Nutrient’s PDF SDK without rebuilding its document layer I replaced our sales training with an AI coach that runs in Slack — here’s what broke Redirecting to: https://securitybuzz.com/cybersecurity-news/why-enterprise-permissions-are-ais-most-dangerous-inheritance/ Nutrient .NET SDK vs. iText Core: Complete comparison for .NET developers DocuVieware: Support’s most frequently asked setup questions Introducing Nutrient Workflow How to convert PDF to Word in C# (.NET) When email and spreadsheets stop working: Work order approval workflows for field teams on the move Compliance with confidence: Why document-centric automation is the foundation of your mission Nutrient expands AI Assistant, automating multistep document workflows inside any application What is document generation? A developer’s guide to PDF generation Document Converter data flow and how real-time watermarks skip the queue PDF/UA compliance guide: Requirements, standards, and best practices Computers still can’t understand you How Athena Intelligence built AI agents for regulated enterprises with Nutrient’s document infrastructure How to convert HTML to PDF (2026): 4 methods from browser print to SDK How to build a document extraction pipeline with Nutrient Vision API OCR vs. intelligent document processing: Choosing the right document extraction engine Beyond OCR: How document intelligence eliminates manual processing in regulated industries Nutrient vs. IronPDF: Complete comparison for .NET developers Nutrient vs. Aspose.PDF: Complete comparison for .NET developers Redirecting to: https://fortune.com/2026/02/19/openclaw-who-is-peter-steinberger-openai-sam-altman-anthropic-moltbook/ Lufthansa Systems uses Nutrient to deliver reliable, scalable PDF rendering for pilots worldwide Nutrient vs. Syncfusion: Complete comparison for .NET developers React’s useTransition: The hook you’re probably using wrong First City Monument Bank streamlines banking processes with Nutrient Workflow Redirecting to: https://www.sdcexec.com/warehousing/automation/article/22957364/nutrient-workflow-automation-the-missing-link-in-supply-chain-efficiency The complete guide to digital signatures: PAdES, CAdES, and XAdES explained Nutrient Python SDK: Production-grade document processing for Python Introducing agentic document editing for web applications with AI Assistant Nutrient vs. QuestPDF: Complete comparison for .NET developers How we fixed the GdPicture license expiration (and what to do if you’re affected) Red team security testing with agentic AI The future of healthcare document automation Best healthcare workflow software compared Nutrient SDK product updates for Q4 2025 How Harvey scaled legal document workflows 50 percent MoM without rebuilding infrastructure HIPAA-compliant document management in hospitals How we optimized rendering performance while handling thousands of annotations in React — Part 2 Automated PII removal with Nutrient API Redirecting to: https://www.devopsdigest.com/2026-low-code-no-code-predictions Redirecting to: https://www.kmworld.com/Articles/Editorial/ViewPoints/Leaders-predict-AI-to-continue-permeating-all-aspects-of-KM-in-2026-172594.aspx What are deep agents and how do they solve complex problems? Whipping up document magic: Your easy-bake recipe for Vue and Nutrient Web SDK 🧁 What I’ve learned about product iteration planning while building SDKs Passwordless document signing: Three-layer security guide New zip folder functionality streamlines file management in Document Automation Server The keyboard shortcuts playbook: Taking control of keyboard events in Nutrient Web SDK From experienced engineer to AI beginner: My unexpected journey AI-assisted manual testing: Handling Safari’s PDF rendering and UI quirks How to keep a 20-year-old SDK up to date How we optimized rendering performance while handling thousands of annotations in React — Part 1 Nutrient announces new executive hires to accelerate next phase of growth Automate document conversion at scale with Python and Nutrient DCS From curiosity to PLG (and AI): My journey to understanding product-led growth Prost to progress: One year as Nutrient Pigeon usage at Nutrient: Bridging native SDKs to Flutter Modernizing CI build servers: How to migrate from Chef to Ansible Unix man pages: AI-friendly documentation since 1971 Consistent hashing for even load distribution Best AI redaction APIs: Complete comparison guide for 2025 Why AI document redaction matters for modern security From coding to coordinating: How AI transformed my workflow What is intelligent document processing (IDP)? A complete guide Enterprise PDF SDKs: Best PSPDFKit (now Nutrient) alternatives Nutrient SDK product updates for Q3 2025 GdPicture support best practices Redacting sensitive data with Nutrient AI redaction API How AI is transforming the customer experience at Nutrient: From instant answers to intelligent support How manual QA uses PR testing between releases
High performance UI using web workers
Ritesh Kumar · 2025-12-03 · via Inside Nutrient

Table of contents

    High performance UI using web workers

    Web workers(opens in a new tab) have been around for more than a decade, but they’re often overlooked as a solution for user interface (UI) performance problems. Most developers think of them as tools for background data processing or API calls, and not for making user interfaces more responsive.

    This article explains web workers through a practical example: Imagine you’re building an application where users can click on points of interest. You want the cursor to “snap” to nearby points for precise selection; when the user hovers near a point, it should automatically highlight the closest one within a specified radius.

    This is exactly what we built with the PointPicker component(opens in a new tab) from our design system, Baseline UI(opens in a new tab). PointPicker allows users to select coordinates on a canvas, and we wanted to add snapping functionality so the cursor automatically highlights the closest point within a specified radius.

    What starts as a simple feature request — “make the cursor snap to nearby points” — becomes a perfect demonstration of how web workers can transform user experience.

    The example shows how to recognize when your UI operations are CPU-intensive enough to benefit from parallel processing, and how to architect solutions that move the right work to background threads.

    The problem: When simple gets complex

    The video above shows the PointPicker component with the snapping functionality we built. The green dots are the snapping points, and the red dot is the current snapped point. The video includes 100,000 points.

    Building snapping functionality sounds trivial. Calculate distances on mouse move, find the nearest point, and highlight it. Done.

    At first, we tried the obvious approach: Calculate the distance from the cursor to every point, find the closest one within our snap radius, and highlight it. When the cursor is within the specified radius of a point, it “snaps” to that point, providing visual feedback and making precise coordinate selection easier.

    This worked perfectly with 100 points. But when we scaled up to thousands of points, the simple distance calculation became a performance bottleneck. Every mouse movement triggered hundreds of calculations, all competing with the UI thread for attention. The cursor started feeling sluggish, UI updates became delayed, and users noticed something was wrong.

    The main thread was drowning in math while trying to handle rendering, event processing, and user interactions. Something had to give.

    The discovery: Spatial indexing

    We needed a better approach. After researching spatial data structures, we discovered spatial indexing. Instead of checking every single point with O(n), we could use a spatial data structure to find nearby points much faster.

    We chose KDBush(opens in a new tab), a flat K-D tree implementation that can find all points within a radius in O(log n + k) time, where k is the number of results found. For small snap radii, k is typically very small, making this dramatically faster than the O(n) brute force approach.

    The web worker solution

    But even with spatial indexing, the calculations were still blocking the main thread. That’s where web workers come in: They let you run heavy calculations in a background thread. The main thread stays free for UI work, while workers handle the computational heavy lifting.

    The architecture

    We designed a two-tier system:

    1. Main thread — Pure UI, with events, animations, and user interactions
    2. Proximity worker — Spatial indexing, with KDBush(opens in a new tab) and distance calculations

    The combination of spatial indexing and workers creates a complete solution: fast algorithms running in parallel threads.

    Worker communication

    Worker communication traditionally involves manual message passing, which can be verbose. We used Comlink(opens in a new tab) to simplify this — it makes worker calls feel like regular function calls, but the core concepts apply to any worker communication approach.

    The proximity worker

    Here’s our worker that handles spatial indexing with KDBush and distance calculations:

    import KDBush from "kdbush";

    import { expose } from "comlink";

    interface Point {

    x: number;

    y: number;

    }

    class PointProximityWorker {

    private index: KDBush<Point> | null = null;

    private snapRadius: number = 50;

    buildIndex(points: Point[]): void {

    // KDBush construction: O(n log n) — one-time cost.

    this.index = new KDBush(

    points,

    (p) => p.x,

    (p) => p.y,

    );

    }

    setSnapRadius(radius: number): void {

    this.snapRadius = radius;

    }

    findNearest(x: number, y: number): Point | null {

    if (!this.index) return null;

    // `KDBush.within()` finds all points within the snap radius - O(log n + k), where k is results found.

    const nearby = this.index.within(x, y, this.snapRadius);

    if (nearby.length === 0) return null;

    // Find the closest point among the candidates.

    let nearest = nearby[0];

    let minDistance = this.calculateDistance(x, y, nearest);

    for (let i = 1; i < nearby.length; i++) {

    const distance = this.calculateDistance(x, y, nearby[i]);

    if (distance < minDistance) {

    minDistance = distance;

    nearest = nearby[i];

    }

    }

    return nearest;

    }

    private calculateDistance(x: number, y: number, point: Point): number {

    return Math.sqrt(Math.pow(x - point.x, 2) + Math.pow(y - point.y, 2));

    }

    }

    expose(PointProximityWorker);

    React integration

    This section will show how to integrate the worker with React: by creating a custom hook for the worker, and then using it in our component.

    The custom hook

    First, we create a hook that manages the worker lifecycle:

    import { wrap } from "comlink";

    import { useEffect, useRef, useState, useCallback } from "react";

    interface Point {

    x: number;

    y: number;

    }

    interface PointProximityHook {

    findNearest: (x: number, y: number) => Promise<Point | null>;

    isReady: boolean;

    }

    export function usePointProximity(

    snapPoints: Point[],

    snapRadius: number,

    ): PointProximityHook {

    const workerRef = useRef<any>(null);

    const [isReady, setIsReady] = useState(false);

    useEffect(() => {

    const worker = new Worker(

    new URL("./PointProximityWorker.ts", import.meta.url),

    { type: "module" },

    );

    const workerApi = wrap(worker);

    workerRef.current = workerApi;

    workerApi.buildIndex(snapPoints);

    workerApi.setSnapRadius(snapRadius);

    setIsReady(true);

    return () => {

    worker.terminate();

    };

    }, [snapPoints, snapRadius]);

    const findNearest = useCallback(

    async (x: number, y: number): Promise<Point | null> => {

    if (!isReady || !workerRef.current) return null;

    return await workerRef.current.findNearest(x, y);

    },

    [isReady],

    );

    return { findNearest, isReady };

    }

    The component

    The final component is clean, but there are some gotchas:

    import React, { useState, useCallback } from "react";

    import { usePointProximity } from "./usePointProximity";

    interface Point {

    x: number;

    y: number;

    }

    interface PointPickerContentProps {

    snapPoints: Point[];

    snapRadius: number;

    onPointSelect: (point: Point) => void;

    }

    export function PointPickerContent({

    snapPoints,

    snapRadius,

    onPointSelect

    }: PointPickerContentProps): JSX.Element {

    const [cursorPosition, setCursorPosition] = useState<Point | null>(null);

    const [snappedPoint, setSnappedPoint] = useState<Point | null>(null);

    const { findNearest, isReady } = usePointProximity(snapPoints, snapRadius);

    const handleMouseMove = useCallback(async (event: React.MouseEvent<HTMLDivElement>) => {

    const rect = event.currentTarget.getBoundingClientRect();

    const x = event.clientX - rect.left;

    const y = event.clientY - rect.top;

    setCursorPosition({ x, y });

    if (isReady) {

    const nearest = await findNearest(x, y);

    setSnappedPoint(nearest);

    }

    }, [findNearest, isReady]);

    return (

    <div onMouseMove={handleMouseMove}>

    {/* Any component that can use the proximity data */}

    <SomeVisualComponent

    points={snapPoints}

    activePoint={snappedPoint}

    />

    </div>

    );

    }

    The transformation

    The results were dramatic. The interface felt much more responsive — the cursor moved smoothly, UI updates happened without delay, and users could interact with thousands of points seamlessly.

    Before — Every mouse movement triggered O(n) calculations that blocked the main thread.

    After — O(log n + k) calculations ran in a background thread.

    The key insight is that the main thread is now completely free to handle user interactions — no more competing for attention between calculations and UI updates.

    What started as a performance problem became a demonstration of how web workers can improve user experience.

    You can see the web worker-powered PointPicker with snapping functionality in action in our live demo(opens in a new tab).

    The broader impact

    This point picker example demonstrates a fundamental shift in web development thinking. Instead of optimizing single-threaded code, we’re leveraging parallel processing.

    The pattern applies to many other scenarios:

    • Real-time data visualization
    • Complex form validation
    • Image processing and manipulation
    • Large dataset filtering
    • Game logic and physics calculations

    Lessons learned

    1. Spatial indexing is crucial — Without KDBush, workers alone wouldn’t solve the O(n) brute force problem.
    2. Communication overhead is manageable — For CPU-intensive tasks, the worker communication cost is negligible.
    3. The main thread stays responsive — Workers keep the UI thread free for user interactions.
    4. Architecture matters — Spatial indexing and workers create a complete solution.
    5. Start simple, then optimize — Basic calculations → KDBush → workers

    Conclusion

    The point picker component demonstrates that web workers can transform sluggish UI components into responsive, scalable solutions. But they’re not a panacea — they require careful consideration of tradeoffs and proper implementation.

    The key insight is recognizing when your UI operations are CPU-intensive enough to benefit from parallel processing. For the right use cases, web workers can make the difference between a broken feature and a delightful one.

    The question isn’t “Can I use web workers?” Rather, it’s “Should I use web workers?” The answer depends on your specific performance requirements and user experience goals.

    Explore related topics

    Try for free Ready to get started?

    Related SDK articles

    Explore more