{"id":33180250,"url":"https://github.com/RyanMyrvold/Performance-Decorators","last_synced_at":"2025-11-20T21:03:32.979Z","repository":{"id":198806056,"uuid":"701602553","full_name":"RyanMyrvold/Performance-Decorators","owner":"RyanMyrvold","description":"Elevate your application's performance with 🚀 Performance Decorators! This comprehensive TypeScript library offers powerful tools for performance monitoring and optimization, making it easier to track and resolve bottlenecks in both Node.js and browser environments.","archived":false,"fork":false,"pushed_at":"2025-10-17T19:53:52.000Z","size":3353,"stargazers_count":48,"open_issues_count":3,"forks_count":4,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-10-18T20:52:59.063Z","etag":null,"topics":["browser","browser-performance","code-optimization","debugging-tool","decorator","developer-tools","node-js","open-source","performance-monitoring","performance-optimization","typescript"],"latest_commit_sha":null,"homepage":"https://github.com/RyanMyrvold/Performance-Decorators","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RyanMyrvold.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-10-07T03:10:28.000Z","updated_at":"2025-09-01T01:19:26.000Z","dependencies_parsed_at":null,"dependency_job_id":"2072367d-6a42-47aa-9a0a-db8de138e33d","html_url":"https://github.com/RyanMyrvold/Performance-Decorators","commit_stats":null,"previous_names":["mervsy/tydy","ryanmyrvold/tydy"],"tags_count":51,"template":false,"template_full_name":null,"purl":"pkg:github/RyanMyrvold/Performance-Decorators","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RyanMyrvold%2FPerformance-Decorators","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RyanMyrvold%2FPerformance-Decorators/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RyanMyrvold%2FPerformance-Decorators/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RyanMyrvold%2FPerformance-Decorators/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RyanMyrvold","download_url":"https://codeload.github.com/RyanMyrvold/Performance-Decorators/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RyanMyrvold%2FPerformance-Decorators/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":285511789,"owners_count":27184240,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-20T02:00:05.334Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["browser","browser-performance","code-optimization","debugging-tool","decorator","developer-tools","node-js","open-source","performance-monitoring","performance-optimization","typescript"],"created_at":"2025-11-16T03:00:41.704Z","updated_at":"2025-11-20T21:03:32.974Z","avatar_url":"https://github.com/RyanMyrvold.png","language":"TypeScript","funding_links":[],"categories":["Built with TypeScript"],"sub_categories":["Decorators"],"readme":"# 🚀 Performance Decorators: A TypeScript Library for Efficient Performance Monitoring \u0026 Optimization\n\nElevate your application's performance with Performance Decorators! This TypeScript library provides powerful tools for seamless performance monitoring and optimization in both Node.js and browser environments. Simplify the task of identifying performance bottlenecks and ensure your applications run efficiently with our easy-to-use decorators.\n\n[![Unit Tests](https://github.com/RyanMyrvold/Performance-Decorators/actions/workflows/npm-test.yml/badge.svg)](https://github.com/RyanMyrvold/Performance-Decorators/actions/workflows/npm-test.yml)\n[![npm](https://img.shields.io/npm/v/performance-decorators)](https://www.npmjs.com/package/performance-decorators)\n[![npm](https://img.shields.io/npm/dm/performance-decorators)](https://www.npmjs.com/package/performance-decorators)\n[![GitHub Issues](https://img.shields.io/github/issues/RyanMyrvold/Performance-Decorators)](https://github.com/RyanMyrvold/Performance-Decorators/issues)\n[![GitHub Repo stars](https://img.shields.io/github/stars/RyanMyrvold/Performance-Decorators?style=social)](https://github.com/RyanMyrvold/Performance-Decorators/stargazers)\n\n## 🌟 Features\n\n### Debugging Decorators\n\n- **LogExecutionTime**: Method Decorator - Logs method execution times, helping pinpoint performance bottlenecks.\n- **LogMemoryUsage**: Method Decorator - Tracks and logs memory usage, aiding in efficient resource management.\n- **LogMethodError**: Method Decorator - Handles and logs method errors, with an option to rethrow them.\n- **WarnMemoryLeak**: Class Decorator - Monitors and warns of potential memory leaks, supporting both Node.js and browsers. Options include setting check intervals, memory usage thresholds, custom logging, and manual garbage collection in Node.js.\n- **WarnPerformanceThreshold**: Method Decorator - Alerts when methods surpass predefined execution time thresholds.\n- **LogNetworkRequests**: Method Decorator - Logs network requests made within the decorated method, providing insights into network performance bottlenecks.\n- **LogReturnValue**: Method Decorator - Logs the return value of a method, aiding in debugging and ensuring methods return expected results.\n\n### Optimization Decorators\n\n- **AutoRetry**: Method Decorator - Automatically retries a failed asynchronous operation until it succeeds or reaches a maximum number of retries.\n- **Debounce**: Method Decorator - Limits the rate at which a function can fire, perfect for handling events like resizing, scrolling, or keypresses.\n- **LazyLoad**: Property Decorator - Delays the initialization of properties until they are first accessed, optimizing resource use and computation time.\n- **Memoize**: Method Decorator - Caches the results of expensive function calls, optimizing performance by avoiding repeated calculations.\n- **Throttle**: Method Decorator - Ensures a function is not called more than once in a specified period, useful for rate-limiting execution of handlers on frequent events.\n\n## 📦 Installation\n\nEasily integrate into your project:\n\n```bash\nnpm install performance-decorators\n```\n\n## 🛠️ Usage Examples\n\n### Debugging Decorators Usage\n\n#### Log Execution Time\n\n```typescript\nimport { LogExecutionTime } from \"performance-decorators/debugging\";\n\nclass PerformanceExample {\n  @LogExecutionTime()\n  quickMethod() {\n    // Simulated task\n  }\n\n  @LogExecutionTime((time, method) =\u003e console.log(`${method} took ${time} ms`))\n  detailedMethod() {\n    // More complex task\n  }\n}\n```\n\n#### Log Memory Usage\n\n```typescript\nimport { LogMemoryUsage } from \"performance-decorators/debugging\";\n\nclass PerformanceExample {\n  @LogMemoryUsage()\n  standardMemoryMethod() {\n    // Memory consuming task\n  }\n\n  @LogMemoryUsage((usedMemory, method) =\u003e\n    console.log(`${method} used ${usedMemory} bytes`),\n  )\n  detailedMemoryMethod() {\n    // Task with detailed memory monitoring\n  }\n}\n```\n\n#### Log Method Error\n\n```typescript\nimport { LogMethodError } from \"performance-decorators/debugging\";\n\nclass PerformanceExample {\n  @LogMethodError()\n  methodWithError() {\n    throw new Error(\"Example error\");\n  }\n\n  @LogMethodError(true, (error, method) =\u003e\n    console.error(`${method} error: ${error.message}`),\n  )\n  methodWithCustomErrorHandling() {\n    throw new Error(\"Custom error\");\n  }\n}\n```\n\n#### Warn Memory Leak\n\n```typescript\nimport WarnMemoryLeak from \"performance-decorators/debugging\";\n\n/**\n * Class decorator to monitor and warn about potential memory leaks.\n * Works in both Node.js and browser environments.\n *\n * @param checkIntervalMs - Interval in milliseconds to check memory usage.\n * @param thresholdPercent - Percentage increase in memory usage to trigger warning.\n * @param logger - Logging function to use for warnings.\n * @param enableManualGC - Enables manual garbage collection in Node.js (requires --expose-gc flag).\n */\nfunction MemoryLeakWarning(\n  checkIntervalMs: number = 30000,\n  thresholdPercent: number = 20,\n  logger: (msg: string) =\u003e void = console.warn,\n  enableManualGC: boolean = false,\n) {\n  return WarnMemoryLeak(\n    checkIntervalMs,\n    thresholdPercent,\n    logger,\n    enableManualGC,\n  );\n}\n\n@MemoryLeakWarning(30000, 20, console.warn, false)\nclass MyMonitoredClass {\n  // Your class implementation\n}\n\n// Create an instance\nconst instance = new MyMonitoredClass();\n```\n\n#### Warn Performance Threshold\n\n```typescript\nimport { WarnPerformanceThreshold } from \"performance-decorators/debugging\";\n\nclass PerformanceExample {\n  @WarnPerformanceThreshold()\n  methodWithDefaultThreshold() {\n    // Task to be monitored\n  }\n\n  @WarnPerformanceThreshold(200, (time, method) =\u003e\n    console.warn(`${method} exceeded ${time} ms`),\n  )\n  methodWithCustomThreshold() {\n    // Another monitored task\n  }\n}\n```\n\n#### Log Network Requests\n\n```typescript\nimport LogNetworkRequests from \"performance-decorators/debugging\";\n\nclass PerformanceExample {\n  @LogNetworkRequests()\n  async fetchData(url: string): Promise\u003cvoid\u003e {\n    const response = await fetch(url);\n    return response.json();\n  }\n\n  @LogNetworkRequests((log) =\u003e {\n    console.log(\n      `Custom Logger - ${log.method} request to ${log.url} took ${log.duration.toFixed(2)}ms`,\n    );\n  })\n  async fetchDataWithCustomLogger(url: string): Promise\u003cvoid\u003e {\n    const response = await fetch(url);\n    return response.json();\n  }\n}\n```\n\n#### Log Return Value\n\n```typescript\nimport LogReturnValue from \"performance-decorators/debugging\";\n\nclass ExampleService {\n  @LogReturnValue()\n  calculateSum(a: number, b: number): number {\n    return a + b;\n  }\n\n  @LogReturnValue((value, methodName) =\u003e\n    console.log(`[${methodName}] returned:`, value),\n  )\n  async fetchData(url: string): Promise\u003cany\u003e {\n    const response = await fetch(url);\n    return response.json();\n  }\n}\n\nconst service = new ExampleService();\nconsole.log(service.calculateSum(3, 4)); // Logs and returns 7\nservice.fetchData(\"https://api.example.com/data\"); // Logs the returned JSON data\n```\n\n### Optimization Decorators Usage\n\n#### AutoRetry\n\n```typescript\nimport { AutoRetry } from \"performance-decorators/optimization\";\n\nclass DataService {\n  @AutoRetry(3, 1000) // Retry up to 3 times with a 1-second delay\n  async fetchData(url: string) {\n    console.log(`Fetching data from ${url}`);\n    const response = await fetch(url);\n    if (!response.ok) {\n      throw new Error(\"Network response was not ok.\");\n    }\n    return response.json();\n  }\n}\n\nconst service = new DataService();\nservice\n  .fetchData(\"https://api.example.com/data\")\n  .then((data) =\u003e console.log(\"Data fetched successfully:\", data))\n  .catch((error) =\u003e console.error(\"Failed to fetch data:\", error));\n```\n\n#### Debounce\n\n```typescript\nimport { Debounce } from \"performance-decorators/optimization\";\n\nclass SearchComponent {\n  @Debounce(300)\n  async onSearch(term: string) {\n    console.log(`Searching for: ${term}`);\n    // Simulate an API call\n    return fetch(`/api/search?q=${encodeURIComponent(term)}`).then((res) =\u003e\n      res.json(),\n    );\n  }\n}\n\nconst searchComponent = new SearchComponent();\nsearchComponent.onSearch(\"hello\");\n```\n\n#### LazyLoad\n\n```typescript\nimport { LazyLoad } from \"performance-decorators/optimization\";\n\nclass ExpensiveComputation {\n  @LazyLoad()\n  get expensiveData() {\n    console.log(\"Computing expensive data\");\n    return Array.from({ length: 1000000 }, (_, i) =\u003e Math.sqrt(i));\n  }\n}\n\nconst computation = new ExpensiveComputation();\nconsole.log(\"ExpensiveComputation instance created\");\n\n// The first access triggers the computation\nconsole.log(computation.expensiveData[1000]); // Initializes and accesses the data\nconsole.log(computation.expensiveData[2000]); // Accesses cached data\n```\n\n#### Memoize\n\n```typescript\nimport { Memoize } from \"performance-decorators/optimization\";\n\nclass Calculator {\n  @Memoize()\n  fibonacci(n: number): number {\n    if (n \u003c= 1) return n;\n    return this.fibonacci(n - 1) + this.fibonacci(n - 2);\n  }\n}\n\nconst calculator = new Calculator();\nconsole.log(calculator.fibonacci(10)); // Computed\nconsole.log(calculator.fibonacci(10)); // Cached result\n```\n\n#### Throttle\n\n```typescript\nimport { Throttle } from \"performance-decorators/optimization\";\n\nclass ScrollHandler {\n  @Throttle(100)\n  onScroll(event: Event) {\n    console.log(\"Scrolling\", event);\n  }\n}\n\nconst handler = new ScrollHandler();\nwindow.addEventListener(\"scroll\", handler.onScroll);\n```\n\n## 📘 API Documentation\n\nRefer to the TypeScript JSDoc comments in the source code for detailed API information. Each decorator is well-documented, providing insights into its usage and configuration.\n\n## 🚧 Contributing\n\nContributions are welcome! Please refer to the project's style and contribution guidelines for submitting patches and additions. Ensure to follow best practices and add tests for new features.\n\n## 📄 License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRyanMyrvold%2FPerformance-Decorators","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FRyanMyrvold%2FPerformance-Decorators","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRyanMyrvold%2FPerformance-Decorators/lists"}