官方介绍
With Projects, you can:
Upload docs and code—like style guides, codebases, or user feedback—so that >every response you get from Claude is grounded in expertise about your Project.
Generate new content like code snippets or diagrams with Claude and see a preview of your Artifacts in a dedicated panel.
Share your most insightful Claude chats and the Artifacts you create on the >Project activity feed, allowing your teammates to learn, explore, and build on shared content.
Projects are available now in the Pro and Team plans.
通过项目功能,您可以:
上传文档和代码——如风格指南、代码库或用户反馈——以确保您从Claude获得的每个回答都基于对您项目的专业知识。
使用Claude生成如代码片段或图表,并在专用面板中预览您的工件。
在项目活动源中分享您最有见地的Claude对话和创建的工件,让您的团队成员能够学习、探索并基于共享内容进行构建。
项目功能现已在Pro和Team计划中提供。
前端界面也大改了,比之前舒服多了
首先演示下优化prompt的project吧
新建一个project,喂给它几本如何写好结构化prompt的文档,再加一篇Claude官方出的Claude prompt写作教程,因为有200K的上下文,所以显示这些知识才占了5%的容量 忽略下面两个我随便实验的问题
接下来的 custom instructions
类似gpt的,不过Claude的这个是只针对单个project的,我随便写写几句
开用!
写一句巨差的prompt做演示:
然后输出结果:
生成的结果prompt展示下:
# Golang Code Optimization Task
## Objective
Thoroughly analyze and optimize the provided Golang project code, prioritizing performance and efficiency improvements. Readability can be sacrificed in favor of achieving maximum optimization.
## Context
The project code provided is part of a Golang application that requires significant performance enhancements. The optimized code will be used in a high-load production environment where every microsecond counts.
## Optimization Guidelines
1. Performance Analysis:
- Conduct a comprehensive performance analysis of the provided code.
- Identify bottlenecks, inefficient algorithms, and resource-intensive operations.
- Use profiling tools (e.g., pprof) to gather metrics on CPU usage, memory allocation, and goroutine behavior.
2. Optimization Techniques:
- Apply advanced Golang optimization techniques, including but not limited to:
- Minimizing allocations and reducing garbage collection pressure
- Utilizing more efficient data structures (e.g., sync.Pool for frequently allocated objects)
- Implementing concurrent patterns where appropriate (e.g., worker pools, pipelines)
- Leveraging compiler optimizations and build tags
- Using unsafe operations where justified by significant performance gains
3. Code Refactoring:
- Rewrite inefficient algorithms with more performant alternatives.
- Eliminate unnecessary computations and redundant operations.
- Optimize loop structures and conditionals for better branch prediction.
4. Memory Management:
- Minimize heap allocations by using stack allocation where possible.
- Implement object reuse strategies to reduce garbage collection overhead.
- Optimize data structures to reduce memory footprint.
5. Concurrency Optimization:
- Identify opportunities for parallelization and implement efficient concurrent patterns.
- Optimize channel usage and goroutine creation/management.
- Use atomic operations and low-level synchronization primitives where appropriate.
6. I/O and Network Optimization:
- Implement efficient I/O patterns (e.g., buffering, asynchronous I/O).
- Optimize network-related code for reduced latency and increased throughput.
7. Third-party Dependencies:
- Evaluate and optimize the use of third-party libraries.
- Consider replacing inefficient external packages with custom, optimized implementations.
8. Benchmarking:
- Provide comprehensive benchmarks comparing the original and optimized code.
- Use the Go testing package's benchmarking features to measure performance improvements.
## Deliverables
1. Optimized Code:
- Provide the fully optimized Golang code with inline comments explaining key optimizations.
2. Performance Report:
- Detailed analysis of performance improvements, including:
- Benchmark results (before and after optimization)
- Profiling data showing reduced CPU usage, memory consumption, and latency
- Explanation of major optimizations and their impact
3. Trade-offs and Considerations:
- List any trade-offs made between performance and other factors (e.g., readability, maintainability).
- Highlight any potential risks or considerations for future maintenance.
4. Further Recommendations:
- Suggest any additional optimizations that could be made with more extensive refactoring or architectural changes.
## Important Notes
- Prioritize runtime performance and resource efficiency over all other considerations.
- Do not hesitate to use low-level optimizations or unsafe operations if they provide substantial performance benefits.
- Ensure that the optimized code maintains the original functionality and passes all existing tests.
- If you encounter any ambiguities or need additional information about the project or its requirements, please ask for clarification before proceeding with the optimization.
By following these guidelines, provide a comprehensive optimization of the Golang project code that maximizes performance and efficiency, even at the expense of code readability or conventional best practices.
以上prompt翻译:
# Golang 代码优化任务
## 目标
彻底分析和优化所提供的 Golang 项目代码,优先提高性能和效率。为了实现最大程度的优化,可以牺牲可读性。
## Context
所提供的项目代码是需要显著提高性能的 Golang 应用程序的一部分。优化后的代码将在高负荷生产环境中使用,在这种环境中,每一微秒都至关重要。
## 优化指南
1.性能分析:
- 对所提供的代码进行全面的性能分析。
- 找出瓶颈、低效算法和资源密集型操作。
- 使用剖析工具(如 pprof)收集有关 CPU 使用率、内存分配和程序行为的指标。
2.优化技术:
- 应用高级 Golang 优化技术,包括但不限于
- 最小化分配和减少垃圾回收压力
- 使用更高效的数据结构(例如,用于频繁分配对象的 sync.Pool)
- 在适当的地方实施并发模式(如工作池、管道)
- 利用编译器优化和构建标签
- 在性能显著提升的情况下使用不安全操作
3.代码重构:
- 用性能更高的替代方案重写低效算法。
- 消除不必要的计算和冗余操作。
- 优化循环结构和条件,以更好地预测分支。
4.内存管理
- 尽可能使用堆栈分配,减少堆分配。
- 实施对象重用策略,减少垃圾回收开销。
- 优化数据结构,减少内存占用。
5.并发优化
- 确定并行化的机会并实施高效的并行模式。
- 优化通道使用和程序创建/管理。
- 酌情使用原子操作和低级同步原语。
6.输入/输出和网络优化
- 实现高效的I/O 模式(如缓冲、异步 I/O)。
- 优化网络相关代码,以减少延迟并提高吞吐量。
7.第三方依赖性:
- 评估并优化第三方库的使用。
- 考虑用定制、优化的实现方式取代低效的外部软件包。
8.基准测试:
- 提供比较原始代码和优化代码的综合基准。
- 使用 Go 测试包的基准功能来衡量性能改进情况。
## 交付成果
1.优化代码:
- 提供经过全面优化的 Golang 代码,并在内联注释中解释关键优化之处。
2.性能报告:
- 性能改进的详细分析,包括
- 基准结果(优化前后)
- 显示 CPU 使用率、内存消耗和延迟降低的剖析数据
- 主要优化及其影响的说明
3.权衡与考虑:
- 列出性能与其他因素(如可读性、可维护性)之间的权衡。
- 强调未来维护的任何潜在风险或考虑因素。
4.进一步建议:
- 提出通过更广泛的重构或架构变更可以实现的其他优化建议。
## 重要说明
- 优先考虑运行时性能和资源效率,然后再考虑其他因素。
- 如果低级优化或不安全操作能带来显著的性能优势,请毫不犹豫地使用它们。
- 确保优化后的代码保持原有功能并通过所有现有测试。
- 如果遇到任何含糊不清之处,或需要有关项目或其要求的更多信息,请在继续优化之前询问清楚。
通过遵循这些指导原则,即使牺牲代码的可读性或传统的最佳实践,也能对 Golang 项目代码进行全面优化,最大限度地提高性能和效率。
可以看到一句随便的话优化过后,直接变成类结构化prompt了,比某些榜单上的生成prompt的GPTs强多了
正好,拿这prompt来测试优化重构我的需求
继续新建一个project,专门给我golang的一个项目来用,毕竟单个project内,上下文全共享
我把这次需求相关的3个golang文件全拖进来,然后新增一个名字为 prompt
,内容为以上刚生成的golang prompt
开用!
可以看到给出的结果明显是按照上面的prompt来的,并且结构很清晰,专注于性能和效率,不再是随便提几个点就完事了
不到20分钟,上面几个对话就把昨天写的3个垃圾代码优化重构完成,为了隐私就不点开截图放代码了,复制到goland没任何报错,打包测了下性能也比昨天的强太多了,还帮我把函数名和常量也都改好了
这只是我演示的一个例子,这个project真的好用,可以上传巨多的项目代码都行,而且单个project内话题和文件全共享,也就是不用像以前那样:
每次给Claude介绍自己代码业务的时候要长篇大论的写一通,上传一堆文件,然后新建话题又要重复来一遍,如果新话题与上个话题有关联,还得把上个话题关键的全复制下来到新的
这些project全都解决了
目前准备跳槽跑路,我刚试了下新建一个面试用的project,再把我做过的项目的技术开发文档和简历全拖进去喂了,又加了几个别人的简历文档示例,给我定制简历特别好,而且还可以扮演专业的面试官,根据这些知识库来针对提问,整理回答话术,有点舒服了