当前位置: 首页 > news >正文

JavaScript系列(58)--性能监控系统详解

JavaScript性能监控系统详解 📊

今天,让我们深入探讨JavaScript的性能监控系统。性能监控对于保证应用的稳定性和用户体验至关重要。

性能监控基础概念 🌟

💡 小知识:JavaScript性能监控是指通过收集和分析各种性能指标,来评估和优化应用性能的过程。这包括页面加载时间、资源使用情况、运行时性能等多个方面。

性能指标收集 📈

// 1. 性能指标收集器
class PerformanceCollector {constructor() {this.metrics = new Map();this.observers = new Set();}// 收集页面加载性能collectPageMetrics() {const timing = performance.timing;const metrics = {dnsTime: timing.domainLookupEnd - timing.domainLookupStart,tcpTime: timing.connectEnd - timing.connectStart,ttfb: timing.responseStart - timing.requestStart,domReady: timing.domContentLoadedEventEnd - timing.navigationStart,loadComplete: timing.loadEventEnd - timing.navigationStart};this.metrics.set('page', metrics);this.notifyObservers('page', metrics);}// 收集资源加载性能collectResourceMetrics() {const resources = performance.getEntriesByType('resource');const metrics = resources.map(resource => ({name: resource.name,type: resource.initiatorType,duration: resource.duration,size: resource.transferSize,startTime: resource.startTime}));this.metrics.set('resources', metrics);this.notifyObservers('resources', metrics);}// 收集运行时性能collectRuntimeMetrics() {const metrics = {memory: performance.memory ? {usedJSHeapSize: performance.memory.usedJSHeapSize,totalJSHeapSize: performance.memory.totalJSHeapSize,jsHeapSizeLimit: performance.memory.jsHeapSizeLimit} : null,fps: this.calculateFPS()};this.metrics.set('runtime', metrics);this.notifyObservers('runtime', metrics);}calculateFPS() {let lastTime = performance.now();let frames = 0;let fps = 0;const updateFPS = () => {const now = performance.now();frames++;if (now > lastTime + 1000) {fps = Math.round((frames * 1000) / (now - lastTime));frames = 0;lastTime = now;}requestAnimationFrame(updateFPS);};requestAnimationFrame(updateFPS);return () => fps;}addObserver(observer) {this.observers.add(observer);}removeObserver(observer) {this.observers.delete(observer);}notifyObservers(type, data) {this.observers.forEach(observer => {observer.update(type, data);});}
}// 2. 性能标记管理器
class PerformanceMarker {constructor() {this.marks = new Map();}mark(name) {performance.mark(name);this.marks.set(name, performance.now());}measure(name, startMark, endMark) {performance.measure(name, startMark, endMark);const measure = performance.getEntriesByName(name, 'measure')[0];return {name,duration: measure.duration,startTime: measure.startTime};}clearMarks() {performance.clearMarks();this.marks.clear();}clearMeasures() {performance.clearMeasures();}
}// 3. 用户交互监控
class InteractionMonitor {constructor() {this.interactions = [];this.setupListeners();}setupListeners() {const observer = new PerformanceObserver(list => {const entries = list.getEntries();this.processInteractions(entries);});observer.observe({ entryTypes: ['first-input', 'layout-shift', 'largest-contentful-paint']});}processInteractions(entries) {entries.forEach(entry => {this.interactions.push({type: entry.entryType,startTime: entry.startTime,duration: entry.duration,value: entry.value,element: entry.target});});}getInteractionMetrics() {return {fid: this.calculateFID(),cls: this.calculateCLS(),lcp: this.calculateLCP()};}calculateFID() {const fidEntry = this.interactions.find(i => i.type === 'first-input');return fidEntry ? fidEntry.duration : null;}calculateCLS() {return this.interactions.filter(i => i.type === 'layout-shift').reduce((sum, entry) => sum + entry.value, 0);}calculateLCP() {const lcpEntries = this.interactions.filter(i => i.type === 'largest-contentful-paint');return lcpEntries.length > 0 ? lcpEntries[lcpEntries.length - 1].startTime : null;}
}

性能分析工具 🔍

// 1. 性能分析器
class PerformanceAnalyzer {constructor() {this.thresholds = new Map();this.issues = [];}setThreshold(metric, value) {this.thresholds.set(metric, value);}analyzeMetrics(metrics) {this.issues = [];// 分析页面加载性能if (metrics.page) {this.analyzePageMetrics(metrics.page);}// 分析资源加载性能if (metrics.resources) {this.analyzeResourceMetrics(metrics.resources);}// 分析运行时性能if (metrics.runtime) {this.analyzeRuntimeMetrics(metrics.runtime);}return this.issues;}analyzePageMetrics(pageMetrics) {if (pageMetrics.ttfb > this.thresholds.get('ttfb')) {this.issues.push({type: 'warning',metric: 'ttfb',message: 'Time to First Byte is too high',value: pageMetrics.ttfb,threshold: this.thresholds.get('ttfb')});}if (pageMetrics.domReady > this.thresholds.get('domReady')) {this.issues.push({type: 'error',metric: 'domReady',message: 'DOM Ready time is too high',value: pageMetrics.domReady,threshold: this.thresholds.get('domReady')});}}analyzeResourceMetrics(resources) {const largeResources = resources.filter(r => r.size > this.thresholds.get('resourceSize'));if (largeResources.length > 0) {this.issues.push({type: 'warning',metric: 'resourceSize',message: 'Large resources detected',resources: largeResources});}}analyzeRuntimeMetrics(runtime) {if (runtime.memory && runtime.memory.usedJSHeapSize > this.thresholds.get('heapSize')) {this.issues.push({type: 'warning',metric: 'memory',message: 'High memory usage detected',value: runtime.memory.usedJSHeapSize});}if (runtime.fps() < this.thresholds.get('fps')) {this.issues.push({type: 'error',metric: 'fps',message: 'Low FPS detected',value: runtime.fps()});}}generateReport() {return {timestamp: new Date(),issueCount: this.issues.length,criticalIssues: this.issues.filter(i => i.type === 'error'),warnings: this.issues.filter(i => i.type === 'warning'),recommendations: this.generateRecommendations()};}generateRecommendations() {return this.issues.map(issue => {switch (issue.metric) {case 'ttfb':return 'Consider using a CDN or optimizing server response time';case 'domReady':return 'Optimize JavaScript execution and reduce blocking resources';case 'resourceSize':return 'Compress and optimize large resources';case 'memory':return 'Check for memory leaks and optimize memory usage';case 'fps':return 'Optimize animations and reduce DOM operations';default:return 'Review and optimize the affected area';}});}
}// 2. 性能监控仪表板
class PerformanceDashboard {constructor() {this.metrics = [];this.charts = new Map();}addMetric(metric) {this.metrics.push({...metric,timestamp: new Date()});this.updateCharts();}createChart(type, data) {// 实现图表创建逻辑return {type,data,render: () => {// 渲染图表}};}updateCharts() {// 更新页面加载时间趋势this.charts.set('loadTime', this.createChart('line',this.metrics.map(m => ({x: m.timestamp,y: m.page.loadComplete}))));// 更新资源使用趋势this.charts.set('resources', this.createChart('bar',this.metrics.map(m => ({x: m.timestamp,y: m.resources.length}))));// 更新内存使用趋势this.charts.set('memory', this.createChart('area',this.metrics.map(m => ({x: m.timestamp,y: m.runtime.memory?.usedJSHeapSize}))));}generateReport(timeRange) {const filteredMetrics = this.metrics.filter(m => m.timestamp >= timeRange.start && m.timestamp <= timeRange.end);return {summary: this.calculateSummary(filteredMetrics),trends: this.calculateTrends(filteredMetrics),issues: this.findIssues(filteredMetrics)};}
}// 3. 性能优化建议生成器
class OptimizationAdvisor {constructor() {this.rules = new Map();}addRule(name, condition, recommendation) {this.rules.set(name, { condition, recommendation });}analyze(metrics) {const recommendations = [];for (const [name, rule] of this.rules) {if (rule.condition(metrics)) {recommendations.push({name,recommendation: rule.recommendation,priority: this.calculatePriority(metrics, name)});}}return recommendations.sort((a, b) => b.priority - a.priority);}calculatePriority(metrics, ruleName) {// 根据性能指标的严重程度计算优化建议的优先级const weights = {loadTime: 0.3,memory: 0.2,fps: 0.3,resources: 0.2};let score = 0;if (metrics.page?.loadComplete > 3000) {score += weights.loadTime;}if (metrics.runtime?.memory?.usedJSHeapSize > metrics.runtime?.memory?.jsHeapSizeLimit * 0.8) {score += weights.memory;}if (metrics.runtime?.fps() < 30) {score += weights.fps;}if (metrics.resources?.length > 50) {score += weights.resources;}return score;}
}

报警和通知系统 🚨

// 1. 报警管理器
class AlertManager {constructor() {this.alerts = new Map();this.handlers = new Map();}addAlert(name, condition, options = {}) {this.alerts.set(name, {condition,threshold: options.threshold,cooldown: options.cooldown || 5 * 60 * 1000, // 5分钟lastTriggered: 0,status: 'inactive'});}addHandler(severity, handler) {if (!this.handlers.has(severity)) {this.handlers.set(severity, []);}this.handlers.get(severity).push(handler);}checkAlerts(metrics) {const now = Date.now();const triggeredAlerts = [];for (const [name, alert] of this.alerts) {if (alert.status === 'inactive' && now - alert.lastTriggered > alert.cooldown) {if (alert.condition(metrics)) {alert.status = 'active';alert.lastTriggered = now;triggeredAlerts.push(name);}}}return triggeredAlerts;}async notify(alertName, data) {const alert = this.alerts.get(alertName);if (!alert) return;const handlers = this.handlers.get(alert.severity) || [];await Promise.all(handlers.map(handler => handler(alertName, data)));}
}// 2. 通知发送器
class NotificationSender {constructor() {this.channels = new Map();}addChannel(name, sender) {this.channels.set(name, sender);}async send(channel, message) {const sender = this.channels.get(channel);if (!sender) {throw new Error(`Channel ${channel} not found`);}try {await sender(message);} catch (error) {console.error(`Failed to send notification to ${channel}:`, error);throw error;}}async broadcast(message) {const results = await Promise.allSettled(Array.from(this.channels.entries()).map(([channel, sender]) => this.send(channel, message)));return results.reduce((summary, result, index) => {const channel = Array.from(this.channels.keys())[index];summary[channel] = result.status === 'fulfilled';return summary;}, {});}
}// 3. 报告生成器
class ReportGenerator {constructor() {this.templates = new Map();}addTemplate(name, template) {this.templates.set(name, template);}generateReport(data, templateName = 'default') {const template = this.templates.get(templateName);if (!template) {throw new Error(`Template ${templateName} not found`);}return template(data);}async saveReport(report, format = 'json') {const fileName = `performance-report-${new Date().toISOString()}.${format}`;switch (format) {case 'json':await fs.writeFile(fileName, JSON.stringify(report, null, 2));break;case 'html':await fs.writeFile(fileName, this.generateHtmlReport(report));break;case 'pdf':await this.generatePdfReport(report, fileName);break;default:throw new Error(`Unsupported format: ${format}`);}return fileName;}generateHtmlReport(report) {// 生成HTML格式的报告return `<!DOCTYPE html><html><head><title>Performance Report</title></head><body><h1>Performance Report</h1><div class="metrics">${this.renderMetrics(report.metrics)}</div><div class="issues">${this.renderIssues(report.issues)}</div><div class="recommendations">${this.renderRecommendations(report.recommendations)}</div></body></html>`;}
}

最佳实践建议 💡

  1. 性能监控策略
// 1. 性能预算管理器
class PerformanceBudgetManager {constructor() {this.budgets = new Map();}setBudget(metric, limit) {this.budgets.set(metric, limit);}checkBudget(metric, value) {const limit = this.budgets.get(metric);if (!limit) return true;return value <= limit;}generateBudgetReport(metrics) {const report = {timestamp: new Date(),violations: [],status: 'pass'};for (const [metric, limit] of this.budgets) {const value = metrics[metric];if (value > limit) {report.violations.push({metric,limit,value,overage: value - limit});report.status = 'fail';}}return report;}
}// 2. 性能监控配置管理器
class MonitoringConfigManager {constructor() {this.config = {sampleRate: 0.1,metrics: new Set(),alertThresholds: new Map()};}setSampleRate(rate) {if (rate < 0 || rate > 1) {throw new Error('Sample rate must be between 0 and 1');}this.config.sampleRate = rate;}enableMetric(metric) {this.config.metrics.add(metric);}disableMetric(metric) {this.config.metrics.delete(metric);}setAlertThreshold(metric, threshold) {this.config.alertThresholds.set(metric, threshold);}shouldCollect() {return Math.random() < this.config.sampleRate;}
}// 3. 性能数据存储管理器
class MetricsStorageManager {constructor() {this.storage = new Map();this.retention = 30 * 24 * 60 * 60 * 1000; // 30天}store(metrics) {const timestamp = Date.now();this.storage.set(timestamp, metrics);this.cleanup();}cleanup() {const cutoff = Date.now() - this.retention;for (const [timestamp] of this.storage) {if (timestamp < cutoff) {this.storage.delete(timestamp);}}}query(timeRange) {const results = [];for (const [timestamp, metrics] of this.storage) {if (timestamp >= timeRange.start && timestamp <= timeRange.end) {results.push({ timestamp, metrics });}}return results;}
}

结语 📝

JavaScript性能监控系统是保证应用性能和用户体验的关键工具。通过本文,我们学习了:

  1. 性能指标的收集和分析
  2. 性能监控工具的实现
  3. 报警和通知系统的构建
  4. 性能报告的生成
  5. 最佳实践和优化建议

💡 学习建议:在实施性能监控时,要注意平衡监控的全面性和系统性能的开销。选择合适的采样率和监控指标,避免监控系统本身成为性能瓶颈。同时,要建立完善的报警机制和响应流程,确保能够及时发现和解决性能问题。


如果你觉得这篇文章有帮助,欢迎点赞收藏,也期待在评论区看到你的想法和建议!👇

终身学习,共同成长。

咱们下一期见

💻

相关文章:

JavaScript系列(58)--性能监控系统详解

JavaScript性能监控系统详解 &#x1f4ca; 今天&#xff0c;让我们深入探讨JavaScript的性能监控系统。性能监控对于保证应用的稳定性和用户体验至关重要。 性能监控基础概念 &#x1f31f; &#x1f4a1; 小知识&#xff1a;JavaScript性能监控是指通过收集和分析各种性能指…...

GESP2023年12月认证C++六级( 第三部分编程题(1)闯关游戏)

参考程序代码&#xff1a; #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <string> #include <map> #include <iostream> #include <cmath> using namespace std;const int N 10…...

git 新项目

新项目git 新建的项目如何进行git 配置git git config --global user.name "cc" git config --global user.email ccexample.com配置远程仓库路径 // 添加 git remote add origin http://gogs/cc/mc.git //如果配错了&#xff0c;删除 git remote remove origin初…...

系统URL整合系列视频一(需求方案)

视频 系统URL整合系列视频一&#xff08;需求方案&#xff09; 视频介绍 &#xff08;全国&#xff09;某大型分布式系统Web资源URL整合需求实现方案讲解。当今社会各行各业对软件系统的web资源访问权限控制越来越严格&#xff0c;控制粒度也越来越细。安全级别提高的同时也增…...

Vue.js 使用组件库构建 UI

Vue.js 使用组件库构建 UI 在 Vue.js 项目中&#xff0c;构建漂亮又高效的用户界面&#xff08;UI&#xff09;是很重要的一环。组件库就是你开发 UI 的好帮手&#xff0c;它可以大大提高开发效率&#xff0c;减少重复工作&#xff0c;还能让你的项目更具一致性和专业感。今天…...

计算图 Compute Graph 和自动求导 Autograd | PyTorch 深度学习实战

前一篇文章&#xff0c;Tensor 基本操作5 device 管理&#xff0c;使用 GPU 设备 | PyTorch 深度学习实战 本系列文章 GitHub Repo: https://github.com/hailiang-wang/pytorch-get-started PyTorch 计算图和 Autograd 微积分之于机器学习Computational Graphs 计算图Autograd…...

51单片机入门_05_LED闪烁(常用的延时方法:软件延时、定时器延时;while循环;unsigned char 可以表示的数字是0~255)

本篇介绍编程实现LED灯闪烁&#xff0c;需要学到一些新的C语言知识。由于单片机执行的速度是非常快的&#xff0c;如果不进行延时的话&#xff0c;人眼是无法识别(停留时间要大于20ms)出LED灯是否在闪烁所以需要学习如何实现软件延时。另外IO口与一个字节位的数据对应关系。 文…...

如何获取sql数据中时间的月份、年份(类型为date)

可用自带的函数month来实现 如&#xff1a; 创建表及插入数据&#xff1a; create table test (id int,begindate datetime) insert into test values (1,2015-01-01) insert into test values (2,2015-02-01) 执行sql语句,获取月份&#xff1a; select MONTH(begindate)…...

【单层神经网络】softmax回归的从零开始实现(图像分类)

softmax回归 该回归分析为后续的多层感知机做铺垫 基本概念 softmax回归用于离散模型预测&#xff08;分类问题&#xff0c;含标签&#xff09; softmax运算本质上是对网络的多个输出进行了归一化&#xff0c;使结果有一个统一的判断标准&#xff0c;不必纠结为什么要这么算…...

使用开源项目:pdf2docx,让PDF转换为Word

目录 1.安装python 2.安装 pdf2docx 3.使用 pdf2docx 转换 PDF 到 Word pdf2docx&#xff1a;GitCode - 全球开发者的开源社区,开源代码托管平台 环境&#xff1a;windows电脑 1.安装python Download Python | Python.org 最好下载3.8以上的版本 安装时记得选择上&#…...

保姆级教程Docker部署KRaft模式的Kafka官方镜像

目录 一、安装Docker及可视化工具 二、单节点部署 1、创建挂载目录 2、运行Kafka容器 3、Compose运行Kafka容器 4、查看Kafka运行状态 三、集群部署 四、部署可视化工具 1、创建挂载目录 2、运行Kafka-ui容器 3、Compose运行Kafka-ui容器 4、查看Kafka-ui运行状态 …...

ChatGPT提问技巧:行业热门应用提示词案例--咨询法律知识

ChatGPT除了可以协助办公&#xff0c;写作文案和生成短视频脚本外&#xff0c;和还可以做为一个法律工具&#xff0c;当用户面临一些法律知识盲点时&#xff0c;可以向ChatGPT咨询获得解答。赋予ChatGPT专家的身份&#xff0c;用户能够得到较为满意的解答。 1.咨询法律知识 举…...

openRv1126 AI算法部署实战之——Tensorflow模型部署实战

在RV1126开发板上部署Tensorflow算法&#xff0c;实时目标检测RTSP传输。视频演示地址 rv1126 yolov5 实时目标检测 rtsp传输_哔哩哔哩_bilibili ​ 一、准备工作 从官网下载tensorflow模型和数据集 手动在线下载&#xff1a; https://github.com/tensorflow/models/b…...

STM32 TIM定时器配置

TIM简介 TIM&#xff08;Timer&#xff09;定时器 定时器可以对输入的时钟进行计数&#xff0c;并在计数值达到设定值时触发中断 16位计数器、预分频器、自动重装寄存器的时基单元&#xff0c;在72MHz计数时钟下可以实现最大59.65s的定时 不仅具备基本的定时中断功能&#xff…...

51单片机 05 矩阵键盘

嘻嘻&#xff0c;LCD在RC板子上可以勉强装上&#xff0c;会有一点歪。 一、矩阵键盘 在键盘中按键数量较多时&#xff0c;为了减少I/O口的占用&#xff0c;通常将按键排列成矩阵形式&#xff1b;采用逐行或逐列的“扫描”&#xff0c;就可以读出任何位置按键的状态。&#xf…...

SSRF 漏洞利用 Redis 实战全解析:原理、攻击与防范

目录 前言 SSRF 漏洞深度剖析 Redis&#xff1a;强大的内存数据库 Redis 产生漏洞的原因 SSRF 漏洞利用 Redis 实战步骤 准备环境 下载安装 Redis 配置漏洞环境 启动 Redis 攻击机远程连接 Redis 利用 Redis 写 Webshell 防范措施 前言 在网络安全领域&#xff0…...

kubernetes学习-配置管理(九)

一、ConfigMap &#xff08;1&#xff09;通过指定目录&#xff0c;创建configmap # 创建一个config目录 [rootk8s-master k8s]# mkdir config[rootk8s-master k8s]# cd config/ [rootk8s-master config]# mkdir test [rootk8s-master config]# cd test [rootk8s-master test…...

python 语音识别

目录 一、语音识别 二、代码实践 2.1 使用vosk三方库 2.2 使用SpeechRecognition 2.3 使用Whisper 一、语音识别 今天识别了别人做的这个app,觉得虽然是个日记app 但是用来学英语也挺好的,能进行语音识别,然后矫正语法,自己说的时候 ,实在不知道怎么说可以先乱说,然…...

一文速览DeepSeek-R1的本地部署——可联网、可实现本地知识库问答:包括671B满血版和各个蒸馏版的部署

前言 自从deepseek R1发布之后「详见《一文速览DeepSeek R1&#xff1a;如何通过纯RL训练大模型的推理能力以比肩甚至超越OpenAI o1(含Kimi K1.5的解读)》」&#xff0c;deepseek便爆火 爆火以后便应了“人红是非多”那句话&#xff0c;不但遭受各种大规模攻击&#xff0c;即便…...

[mmdetection]fast-rcnn模型训练自己的数据集的详细教程

本篇博客是由本人亲自调试成功后的学习笔记。使用了mmdetection项目包进行fast-rcnn模型的训练&#xff0c;数据集是自制图像数据。废话不多说&#xff0c;下面进入训练步骤教程。 注&#xff1a;本人使用linux服务器进行展示&#xff0c;Windows环境大差不差。另外&#xff0…...

未来机器人的大脑:如何用神经网络模拟器实现更智能的决策?

编辑&#xff1a;陈萍萍的公主一点人工一点智能 未来机器人的大脑&#xff1a;如何用神经网络模拟器实现更智能的决策&#xff1f;RWM通过双自回归机制有效解决了复合误差、部分可观测性和随机动力学等关键挑战&#xff0c;在不依赖领域特定归纳偏见的条件下实现了卓越的预测准…...

挑战杯推荐项目

“人工智能”创意赛 - 智能艺术创作助手&#xff1a;借助大模型技术&#xff0c;开发能根据用户输入的主题、风格等要求&#xff0c;生成绘画、音乐、文学作品等多种形式艺术创作灵感或初稿的应用&#xff0c;帮助艺术家和创意爱好者激发创意、提高创作效率。 ​ - 个性化梦境…...

测试微信模版消息推送

进入“开发接口管理”--“公众平台测试账号”&#xff0c;无需申请公众账号、可在测试账号中体验并测试微信公众平台所有高级接口。 获取access_token: 自定义模版消息&#xff1a; 关注测试号&#xff1a;扫二维码关注测试号。 发送模版消息&#xff1a; import requests da…...

Vue记事本应用实现教程

文章目录 1. 项目介绍2. 开发环境准备3. 设计应用界面4. 创建Vue实例和数据模型5. 实现记事本功能5.1 添加新记事项5.2 删除记事项5.3 清空所有记事 6. 添加样式7. 功能扩展&#xff1a;显示创建时间8. 功能扩展&#xff1a;记事项搜索9. 完整代码10. Vue知识点解析10.1 数据绑…...

ubuntu搭建nfs服务centos挂载访问

在Ubuntu上设置NFS服务器 在Ubuntu上&#xff0c;你可以使用apt包管理器来安装NFS服务器。打开终端并运行&#xff1a; sudo apt update sudo apt install nfs-kernel-server创建共享目录 创建一个目录用于共享&#xff0c;例如/shared&#xff1a; sudo mkdir /shared sud…...

如何在看板中体现优先级变化

在看板中有效体现优先级变化的关键措施包括&#xff1a;采用颜色或标签标识优先级、设置任务排序规则、使用独立的优先级列或泳道、结合自动化规则同步优先级变化、建立定期的优先级审查流程。其中&#xff0c;设置任务排序规则尤其重要&#xff0c;因为它让看板视觉上直观地体…...

dedecms 织梦自定义表单留言增加ajax验证码功能

增加ajax功能模块&#xff0c;用户不点击提交按钮&#xff0c;只要输入框失去焦点&#xff0c;就会提前提示验证码是否正确。 一&#xff0c;模板上增加验证码 <input name"vdcode"id"vdcode" placeholder"请输入验证码" type"text&quo…...

Golang dig框架与GraphQL的完美结合

将 Go 的 Dig 依赖注入框架与 GraphQL 结合使用&#xff0c;可以显著提升应用程序的可维护性、可测试性以及灵活性。 Dig 是一个强大的依赖注入容器&#xff0c;能够帮助开发者更好地管理复杂的依赖关系&#xff0c;而 GraphQL 则是一种用于 API 的查询语言&#xff0c;能够提…...

Android 之 kotlin 语言学习笔记三(Kotlin-Java 互操作)

参考官方文档&#xff1a;https://developer.android.google.cn/kotlin/interop?hlzh-cn 一、Java&#xff08;供 Kotlin 使用&#xff09; 1、不得使用硬关键字 不要使用 Kotlin 的任何硬关键字作为方法的名称 或字段。允许使用 Kotlin 的软关键字、修饰符关键字和特殊标识…...

LeetCode - 199. 二叉树的右视图

题目 199. 二叉树的右视图 - 力扣&#xff08;LeetCode&#xff09; 思路 右视图是指从树的右侧看&#xff0c;对于每一层&#xff0c;只能看到该层最右边的节点。实现思路是&#xff1a; 使用深度优先搜索(DFS)按照"根-右-左"的顺序遍历树记录每个节点的深度对于…...