Skip to content

Commit 3024bdc

Browse files
committed
update changelog from module git history and document latest HTTP benchmark optimizations
1 parent 0049f2a commit 3024bdc

8 files changed

Lines changed: 495 additions & 146 deletions

File tree

CHANGELOG.md

Lines changed: 212 additions & 110 deletions
Large diffs are not rendered by default.

include/vix/Version.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @file Version.hpp
3+
*
4+
* Central version metadata for the Vix core runtime.
5+
*/
6+
#ifndef VIX_VERSION_HPP
7+
#define VIX_VERSION_HPP
8+
9+
#include <string_view>
10+
11+
namespace vix
12+
{
13+
inline constexpr std::string_view VERSION = "v2.7.0";
14+
inline constexpr std::string_view CORE_VERSION = VERSION;
15+
}
16+
17+
#endif // VIX_VERSION_HPP

include/vix/core.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <vix/print.hpp>
2323
#include <vix/console.hpp>
2424
#include <vix/app/App.hpp>
25+
#include <vix/Version.hpp>
2526
#include <vix/server/HTTPServer.hpp>
2627
#include <vix/router/Router.hpp>
2728
#include <vix/http/IRequestHandler.hpp>

include/vix/http/Request.hpp

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#ifndef VIX_REQUEST_HPP
1313
#define VIX_REQUEST_HPP
1414

15+
#include <functional>
1516
#include <memory>
1617
#include <stdexcept>
1718
#include <string>
@@ -27,6 +28,39 @@
2728

2829
namespace vix::http
2930
{
31+
#ifndef VIX_HTTP_TRANSPARENT_STRING_TYPES
32+
#define VIX_HTTP_TRANSPARENT_STRING_TYPES
33+
struct TransparentStringHash
34+
{
35+
using is_transparent = void;
36+
37+
std::size_t operator()(std::string_view value) const noexcept
38+
{
39+
return std::hash<std::string_view>{}(value);
40+
}
41+
42+
std::size_t operator()(const std::string &value) const noexcept
43+
{
44+
return std::hash<std::string_view>{}(value);
45+
}
46+
47+
std::size_t operator()(const char *value) const noexcept
48+
{
49+
return std::hash<std::string_view>{}(value ? std::string_view{value} : std::string_view{});
50+
}
51+
};
52+
53+
struct TransparentStringEqual
54+
{
55+
using is_transparent = void;
56+
57+
bool operator()(std::string_view a, std::string_view b) const noexcept
58+
{
59+
return a == b;
60+
}
61+
};
62+
#endif
63+
3064
/**
3165
* @brief Lightweight native HTTP request object for Vix.
3266
*
@@ -43,7 +77,7 @@ namespace vix::http
4377
using QueryMap = std::unordered_map<std::string, std::string>;
4478

4579
/** @brief Map of HTTP headers. */
46-
using HeaderMap = std::unordered_map<std::string, std::string>;
80+
using HeaderMap = std::unordered_map<std::string, std::string, TransparentStringHash, TransparentStringEqual>;
4781

4882
/** @brief Shared pointer type for request-scoped state storage. */
4983
using StatePtr = std::shared_ptr<vix::http::RequestState>;
@@ -229,14 +263,14 @@ namespace vix::http
229263
*/
230264
std::string header(std::string_view name) const
231265
{
232-
auto it = headers_.find(std::string(name));
266+
auto it = headers_.find(name);
233267
return it == headers_.end() ? std::string{} : it->second;
234268
}
235269

236270
/** @brief Return true if a header exists. */
237271
bool has_header(std::string_view name) const
238272
{
239-
return headers_.find(std::string(name)) != headers_.end();
273+
return headers_.find(name) != headers_.end();
240274
}
241275

242276
/** @brief Set or replace one header. */
@@ -248,7 +282,11 @@ namespace vix::http
248282
/** @brief Remove a header if present. */
249283
void remove_header(std::string_view name)
250284
{
251-
headers_.erase(std::string(name));
285+
const auto it = headers_.find(name);
286+
if (it != headers_.end())
287+
{
288+
headers_.erase(it);
289+
}
252290
}
253291

254292
/** @brief Parse and return the body as JSON, computed lazily. */

include/vix/http/Response.hpp

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#ifndef VIX_RESPONSE_HPP
1313
#define VIX_RESPONSE_HPP
1414

15+
#include <atomic>
1516
#include <chrono>
1617
#include <cstdint>
1718
#include <ctime>
@@ -136,7 +137,10 @@ namespace vix::http
136137
/** @brief Remove a header if present. */
137138
void remove_header(std::string_view name)
138139
{
139-
headers_.erase(std::string(name));
140+
if (const auto it = headers_.find(std::string(name)); it != headers_.end())
141+
{
142+
headers_.erase(it);
143+
}
140144
}
141145

142146
/** @brief Remove all headers. */
@@ -245,6 +249,35 @@ namespace vix::http
245249
return oss.str();
246250
}
247251

252+
/** @brief Return an HTTP date cached for the current second. */
253+
static const std::string &cached_http_date_now() noexcept
254+
{
255+
using clock = std::chrono::system_clock;
256+
257+
static std::string cached = http_date_now();
258+
static auto last_tick = clock::now();
259+
static std::atomic_flag lock = ATOMIC_FLAG_INIT;
260+
261+
const auto now = clock::now();
262+
if (now - last_tick < std::chrono::seconds(1))
263+
{
264+
return cached;
265+
}
266+
267+
while (lock.test_and_set(std::memory_order_acquire))
268+
{
269+
}
270+
271+
if (clock::now() - last_tick >= std::chrono::seconds(1))
272+
{
273+
cached = http_date_now();
274+
last_tick = clock::now();
275+
}
276+
277+
lock.clear(std::memory_order_release);
278+
return cached;
279+
}
280+
248281
/** @brief Apply common headers (Server, Date) if absent. */
249282
static void common_headers(Response &res) noexcept
250283
{
@@ -255,7 +288,7 @@ namespace vix::http
255288

256289
if (!res.has_header("Date"))
257290
{
258-
res.set_header("Date", http_date_now());
291+
res.set_header("Date", cached_http_date_now());
259292
}
260293
}
261294

include/vix/session/Session.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ namespace vix::session
5252
std::string method{};
5353
std::string target{};
5454
std::string version{"HTTP/1.1"};
55-
std::unordered_map<std::string, std::string> headers{};
55+
vix::http::Request::HeaderMap headers{};
5656
std::size_t content_length{0};
5757
bool keep_alive{true};
5858
};
@@ -125,6 +125,9 @@ namespace vix::session
125125
*/
126126
static bool is_normal_disconnect(const std::system_error &e) noexcept;
127127

128+
/** @brief Read and handle one ultra-fast /bench request in VIX_BENCH_MODE. */
129+
task<bool> handle_bench_request_fast();
130+
128131
/** @brief Read and parse the next HTTP request from the socket. */
129132
task<std::optional<vix::http::Request>> read_request();
130133

src/app/App.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*
1313
*/
1414
#include <vix/app/App.hpp>
15+
#include <vix/Version.hpp>
1516

1617
#include <vix/openapi/register_docs.hpp>
1718
#include <vix/router/Router.hpp>
@@ -276,7 +277,7 @@ namespace vix
276277

277278
if (vix::utils::env_bool("VIX_DOCS", true))
278279
{
279-
vix::openapi::register_openapi_and_docs(*router_, "Vix API", "2.6.0");
280+
vix::openapi::register_openapi_and_docs(*router_, "Vix API", "2.7.0");
280281
}
281282

282283
install_access_logs(*this);
@@ -555,7 +556,7 @@ namespace vix
555556

556557
vix::utils::ServerReadyInfo info;
557558
info.app = "vix.cpp";
558-
info.version = "v2.6.0";
559+
info.version = std::string(vix::VERSION);
559560
info.ready_ms = ready_ms;
560561
info.mode = dev_mode_ ? "dev" : "run";
561562

0 commit comments

Comments
 (0)