perf: Ускорена сериализация/десериализация json и формирование статистики#45
perf: Ускорена сериализация/десериализация json и формирование статистики#45
Conversation
…тики - Снижены накладные расходы на рефлексию при сериализации и десериализации - Оптимизировано построение упорядоченных замеров времени в статистике бенчмарка
📝 WalkthroughWalkthroughCaching layers added to JSON serializer and deserializer classes to cache property metadata and method handler lookups per type, reducing recomputation during serialization/deserialization cycles. Statistics class refactored to extract sorting logic into a dedicated procedure. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/BenchmarkOneScript/core/custom-jason/Классы/ДесериализаторJsonBench.os (1)
401-435: Code duplication with serializer.
ПрочитатьОбработчикиТипаis nearly identical to the serializer's version, differing only in the handler names. Consider extracting this to a shared utility module with the handler names as a parameter.This would reduce maintenance burden if the handler-caching logic needs updates in the future.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/BenchmarkOneScript/core/custom-jason/Классы/ДесериализаторJsonBench.os` around lines 401 - 435, The ПрочитатьОбработчикиТипа function duplicates logic from the serializer; extract the common handler-discovery and caching logic into a shared utility (e.g., BuildHandlerCache or ReadHandlersForType) that accepts the type (Тип) and an array of handler names (ИменаОбработчиков) as parameters; have this new function use Рефлектор.ПолучитьТаблицуМетодов, РаботаСАннотациями.НайтиАннотацию and КэшОбработчиков for caching, then replace both ПрочитатьОбработчикиТипа and the serializer's counterpart to call the shared utility passing their respective handler name lists to eliminate duplication.src/BenchmarkOneScript/core/custom-jason/Классы/СериализаторJsonBench.os (1)
276-301: Consider lazy array initialization for slight efficiency gain.The inner loop creates
СвойстваМетодовarray for each handler name on every method iteration, even when no annotation is found. Moving array creation inside the annotation check would avoid unnecessary allocations.♻️ Optional optimization
Для Каждого ИмяОбработчика Из ИменаОбработчиков Цикл - СвойстваМетодов = Обработчики[ИмяОбработчика]; - - Если СвойстваМетодов = Неопределено Тогда - СвойстваМетодов = Новый Массив(); - Обработчики[ИмяОбработчика] = СвойстваМетодов; - КонецЕсли; - АннотацияОбработчика = РаботаСАннотациями.НайтиАннотацию(СвойстваМетода.Аннотации, ИмяОбработчика); Если АннотацияОбработчика <> Неопределено Тогда + СвойстваМетодов = Обработчики[ИмяОбработчика]; + Если СвойстваМетодов = Неопределено Тогда + СвойстваМетодов = Новый Массив(); + Обработчики[ИмяОбработчика] = СвойстваМетодов; + КонецЕсли; СвойстваМетодов.Добавить(СвойстваМетода); Прервать; КонецЕсли;🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/BenchmarkOneScript/core/custom-jason/Классы/СериализаторJsonBench.os` around lines 276 - 301, The inner loop currently allocates a new array for each handler name on every method iteration by doing СвойстваМетодов = Новый Массив() before checking annotations; change the logic in the loop over ИменаОбработчиков so you only create and assign Обработчики[ИмяОбработчика] = Новый Массив() when АннотацияОбработчика (from РаботаСАннотациями.НайтиАннотацию(СвойстваМетода.Аннотации, ИмяОбработчика)) is found and you are about to call СвойстваМетодов.Добавить(СвойстваМетода); keep the rest (Обработчики, КэшОбработчиков.Вставить(Тип, Обработчики), Возврат Обработчики) unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/BenchmarkOneScript/core/custom-jason/Классы/ДесериализаторJsonBench.os`:
- Around line 401-435: The ПрочитатьОбработчикиТипа function duplicates logic
from the serializer; extract the common handler-discovery and caching logic into
a shared utility (e.g., BuildHandlerCache or ReadHandlersForType) that accepts
the type (Тип) and an array of handler names (ИменаОбработчиков) as parameters;
have this new function use Рефлектор.ПолучитьТаблицуМетодов,
РаботаСАннотациями.НайтиАннотацию and КэшОбработчиков for caching, then replace
both ПрочитатьОбработчикиТипа and the serializer's counterpart to call the
shared utility passing their respective handler name lists to eliminate
duplication.
In `@src/BenchmarkOneScript/core/custom-jason/Классы/СериализаторJsonBench.os`:
- Around line 276-301: The inner loop currently allocates a new array for each
handler name on every method iteration by doing СвойстваМетодов = Новый Массив()
before checking annotations; change the logic in the loop over ИменаОбработчиков
so you only create and assign Обработчики[ИмяОбработчика] = Новый Массив() when
АннотацияОбработчика (from
РаботаСАннотациями.НайтиАннотацию(СвойстваМетода.Аннотации, ИмяОбработчика)) is
found and you are about to call СвойстваМетодов.Добавить(СвойстваМетода); keep
the rest (Обработчики, КэшОбработчиков.Вставить(Тип, Обработчики), Возврат
Обработчики) unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 9b9b228a-b003-4928-b315-18ed9bcd265d
📒 Files selected for processing (3)
src/BenchmarkOneScript/core/custom-jason/Классы/ДесериализаторJsonBench.ossrc/BenchmarkOneScript/core/custom-jason/Классы/СериализаторJsonBench.ossrc/BenchmarkOneScript/core/Классы/СтатистикаБенчмарка.os

Summary by CodeRabbit