145-java-refactoring-high-performance
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseJava rules for High Performance
Java高性能优化规则
Identify and apply practical Java high-performance techniques using a measure-first approach, with emphasis on allocation reduction, data layout, concurrency discipline, and evidence-based validation.
What is covered in this Skill?
- Measure-first workflow for Java code optimization
- JVM/runtime-aware coding guidance
- Allocation reduction techniques with bad/good patterns
- CPU hot-path simplification and loop-level efficiency patterns
- Concurrency/backpressure and timeout/cancellation discipline
- I/O, parsing, and serialization efficiency patterns
- Persistence/query and caching strategy guidance
- Java-centric decision workflow: keep/revert based on measured impact
Scope: Practical optimization in application code and APIs. Apply only where profiling indicates real bottlenecks.
采用先测量后优化的方法,识别并应用实用的Java高性能技术,重点关注内存分配减少、数据布局、并发规范以及基于实证的验证。
本Skill涵盖哪些内容?
- Java代码优化的先测量后执行工作流
- 基于JVM/运行时的编码指导
- 包含反例/正例的内存分配减少技巧
- CPU热点路径简化与循环级效率模式
- 并发/背压与超时/取消规范
- I/O、解析与序列化效率模式
- 持久化/查询与缓存策略指导
- 基于Java的决策流程:根据测量结果决定保留/回退优化
适用范围: 应用代码与API中的实用优化。仅在性能分析显示存在实际瓶颈时应用。
Constraints
约束条件
Performance optimization must be evidence-driven and safe, focused on Java code changes that preserve correctness and maintainability.
- MEASURE-FIRST: Establish baseline behavior and identify Java code hot paths before optimization
- NO PREMATURE OPTIMIZATION: Only optimize code paths identified by profiling evidence
- BEFORE APPLYING: Read the relevant reference(s) for bad/good examples and measurement workflow
- EDGE CASE: If hotspot evidence is unclear, ask clarifying questions before changing code
性能优化必须基于实证且安全,聚焦于能保持代码正确性与可维护性的Java代码变更。
- 先测量后优化:在优化前确定基准行为并识别Java代码的热点路径
- 禁止过早优化:仅对性能分析证实的代码路径进行优化
- 应用前须知:阅读相关参考文档中的反例/正例以及测量工作流
- 特殊情况:若热点证据不明确,在修改代码前先提出澄清问题
When to use this skill
何时使用本Skill
- Review Java code for high performance
- Optimize Java hot path
- Reduce Java allocations
- Improve Java latency
- Improve Java throughput
- 评审Java代码以提升高性能
- 优化Java热点路径
- 减少Java内存分配
- 提升Java延迟性能
- 提升Java吞吐量
Workflow
工作流程
- Identify Java hotspot and baseline behavior
Confirm the performance-sensitive Java path and baseline behavior before changing code.
- Select the relevant reference(s) by bottleneck
Pick and read only the reference(s) matching the observed hotspot: for allocation pressure, primitives vs. wrappers, escape analysis, collection sizing, data layout, and deduplication; for CPU-bound hot paths, bit-level parsing, branchless arithmetic, loop unrolling, Unsafe caution, and SIMD/vectorization; for code shape, lambdas, API return conventions, parsing syntax, I/O strategy, concurrency, and control-flow improvements.
references/145-refactoring-high-performance-java-memory-allocation.mdreferences/145-refactoring-high-performance-java-cpu.mdreferences/145-refactoring-high-performance-java-code-syntax.md- Apply targeted optimizations
Implement minimal, evidence-backed changes scoped to the chosen domain(s): memory/allocation, CPU/low-level, or code shape/control flow (and adjacent concurrency, I/O, and persistence/caching in Java code).
- Validate and compare code-level outcomes
Compare before/after behavior and keep only Java code changes with meaningful, verified gains.
- 识别Java热点路径与基准行为
在修改代码前,确认性能敏感的Java路径及基准行为。
- 根据瓶颈选择相关参考文档
仅选择与观察到的热点匹配的参考文档: 适用于内存分配压力、基本类型与包装类型、逃逸分析、集合大小设置、数据布局与去重; 适用于CPU密集型热点路径、位级解析、无分支算术、循环展开、Unsafe使用注意事项以及SIMD/向量化; 适用于代码结构、lambda表达式、API返回约定、解析语法、I/O策略、并发与控制流改进。
references/145-refactoring-high-performance-java-memory-allocation.mdreferences/145-refactoring-high-performance-java-cpu.mdreferences/145-refactoring-high-performance-java-code-syntax.md- 应用针对性优化
实施最小化、基于实证的变更,范围限于所选领域:内存/分配、CPU/底层、或代码结构/控制流(以及Java代码中相关的并发、I/O、持久化/缓存)。
- 验证并比较代码层面的结果
比较优化前后的行为,仅保留有显著、可验证收益的Java代码变更。
Reference
参考资料
For detailed guidance, examples, and constraints, see:
- references/145-refactoring-high-performance-java-memory-allocation.md
- references/145-refactoring-high-performance-java-cpu.md
- references/145-refactoring-high-performance-java-code-syntax.md
如需详细指导、示例与约束条件,请参阅:
- references/145-refactoring-high-performance-java-memory-allocation.md
- references/145-refactoring-high-performance-java-cpu.md
- references/145-refactoring-high-performance-java-code-syntax.md