Posts

Showing posts with the label performance optimization

Using D3 and Canvas to Visualize Data on NextJS

Image
Introduction In the previous article, I introduced how to use D3 to visualize data as charts. For most chart visualization needs, using D3 to create individual HTML DOM elements is sufficient. However, if you need to build a web application with superior performance to handle complex cases with relatively large datasets, then applying Canvas is a good solution for you Canvas is an HTML5 element that allows for extremely high-performance 2D graphic drawing via JavaScript. Unlike SVG, which creates separate DOM elements for each object, Canvas operates as a "blank canvas" where pixels are drawn directly onto a single surface. For instance, in real-world products like Figma, Canva, and TradingView, they all utilize Canvas to handle complex graphical operations. Outstanding advantages of Canvas include: superior render speed when processing thousands of objects simultaneously, memory resource savings as it does not increase the size of the DOM tree, and flexible customization for...

Optimizing Konva Performance with rAF

Image
Introduction requestAnimationFrame (rAF) is a powerful browser API that helps achieve smoother interface changes by synchronizing rendering with the screen's refresh rate. Using rAF helps optimize performance, minimize lag (jank), and save energy by pausing calculations when the browser tab is inactive. Prerequisites In this article, I will continue to use the example from the previous article to optimize, so I will not provide the complete code but only the updated part; please refer to the previous article for the full content. Detail Update the OptimizedCanvas.tsx file as follows: import Konva from 'konva' import React , {useCallback, useEffect, useMemo, useRef, useState} from 'react' import {Layer, Stage} from 'react-konva' import useImage from 'use-image' import {ShapeItem} from './ShapeItem' import type {ShapeData, ViewRect} from './type' import {generateData, HEIGHT, IMAGE_URL, TOTAL_OBJECTS, WIDTH} from ...

Guide to Querying and Pagination with AWS DynamoDB in NestJS

Image
Introduction In my previous article, I provided a basic guide on initializing and using AWS DynamoDB, but in this article, we will delve deeper into QueryCommand. In AWS DynamoDB, the Query method allows you to search for data based on the primary key (Partition Key) and filter conditions (Sort Key). To optimize performance and cost, DynamoDB supports a Pagination mechanism through the ExclusiveStartKey and LastEvaluatedKey parameters. Applying pagination not only reduces the data transfer load but also enables the application to handle large data tables smoothly, ensuring system stability. Detail Use AWS CDK to create the file lib/dynamodb-gsi-stack.ts import * as cdk from "aws-cdk-lib" import * as dynamodb from "aws-cdk-lib/aws-dynamodb" import { Construct } from "constructs" export class DynamoDbGsiStack extends cdk . Stack { constructor ( scope : Construct , id : string , props ?: cdk . StackProps ) { super (scope, id, props) ...