一键导入
horse-performance-tuning
Guide for optimizing performance, tuning memory alocations, handling large payloads, and adjusting provider execution pipelines.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Guide for optimizing performance, tuning memory alocations, handling large payloads, and adjusting provider execution pipelines.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Guidelines and workflows for developing and maintaining regular expressions and optional parameter routing features in the Horse framework.
Guidelines for registering, executing, and optimizing native high-precision telemetry hooks (AddOnTelemetry) in the Horse Web Framework.
Guidelines for instantiating and configuring independent Horse server instances (THorseInstance) running concurrently on different ports.
Guide for setting up thread-safe database connection pooling (FireDAC / UniDAC) in multithreaded Horse applications.
Guide for managing request-scoped contextual services and IoC (dependency injection) in Delphi and Lazarus.
Guide to using standard Horse middlewares (CORS, Jhonson, compression, basic-auth, logger) and pipeline registration order.
| name | horse-performance-tuning |
| description | Guide for optimizing performance, tuning memory alocations, handling large payloads, and adjusting provider execution pipelines. |
To exploit the raw speed and low latency of the Horse framework, write handlers that avoid CPU bottlenecks and memory allocation overhead.
Memory allocations (creating objects, large arrays, or concatenating strings) require thread synchronization locks in the memory manager, which slows down concurrent execution under heavy loads.
TJSONObject instances.+ operator. Use TStringBuilder instead to avoid repeatedly reallocating memory on the heap.// Inefficient (creates hundreds of temporary heap strings)
for I := 1 to 1000 do
LResponseText := LResponseText + LData[I];
// Efficient
LBuilder := TStringBuilder.Create;
try
for I := 1 to 1000 do
LBuilder.Append(LData[I]);
Res.Send(LBuilder.ToString);
finally
LBuilder.Free;
end;
When transferring large JSON strings, files, or reports, do not load the entire file contents into a string variable. Stream it directly to the socket chunk-by-chunk using Res.SendFile or Res.Download to maintain a low RAM profile.
TStringList or byte array.TFileStream directly to the response (letting Horse stream it efficiently).procedure ServeFileHandler(Req: THorseRequest; Res: THorseResponse);
var
LStream: TFileStream;
begin
LStream := TFileStream.Create('C:\data\largefile.zip', fmOpenRead or fmShareDenyWrite);
Res.Status(THTTPStatus.OK).SendFile(LStream, 'largefile.zip');
// Do NOT free LStream. Horse takes ownership of the stream.
end;
The default Indy provider (Horse.Provider.Console) uses a thread-per-connection model. Under massive concurrency (thousands of connections), this model incurs thread-switching overhead.
horse-provider-crosssocket or horse-provider-mormot for asynchronous, non-blocking I/O.Horse.Provider.HTTPsys. Since it runs in kernel-mode, it bypasses user-to-kernel context switches, achieving near-native OS speed.When building Horse applications for production, ensure the compiler optimization is turned on and debugging symbols are disabled (configured in your .dproj or boss.json script):
{$ASSERTIONS OFF} or {$C-}).{$OPTIMIZATION ON} or {$O+}).