Skip to content

perf: Ускорена сериализация/десериализация json и формирование статистики#45

Merged
Stivo182 merged 1 commit intomainfrom
perf/jason-stats
Mar 21, 2026
Merged

perf: Ускорена сериализация/десериализация json и формирование статистики#45
Stivo182 merged 1 commit intomainfrom
perf/jason-stats

Conversation

@Stivo182
Copy link
Owner

@Stivo182 Stivo182 commented Mar 21, 2026

  • Снижены накладные расходы на рефлексию при сериализации и десериализации
  • Оптимизировано построение упорядоченных замеров времени в статистике бенчмарка

Summary by CodeRabbit

  • Refactor
    • Improved serialization and deserialization performance through optimized caching of type metadata and method handlers.
    • Enhanced benchmark statistics computation efficiency by streamlining value sorting operations.

…тики

- Снижены накладные расходы на рефлексию при сериализации и десериализации
- Оптимизировано построение упорядоченных замеров времени в статистике бенчмарка
@coderabbitai
Copy link

coderabbitai bot commented Mar 21, 2026

📝 Walkthrough

Walkthrough

Caching 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

Cohort / File(s) Summary
Custom JSON Handler Caching
src/BenchmarkOneScript/core/custom-jason/Классы/ДесериализаторJsonBench.os, src/BenchmarkOneScript/core/custom-jason/Классы/СериализаторJsonBench.os
Both deserializer and serializer classes now maintain per-type caches (КэшОбработчиков, КэшСвойствТипов, КэшГеттеровСвойств) initialized on object creation. New helper functions (ПрочитатьСвойстваТипа, ПрочитатьОбработчикиТипа, ПрочитатьГеттерыСвойствТипа) build and cache property/handler metadata from reflection, avoiding repeated scanning. Handler invocation and property serialization now use cached lookups with early-exit optimization.
Statistics Sorting Refactoring
src/BenchmarkOneScript/core/Классы/СтатистикаБенчмарка.os
Extracted inline time-measure ordering computation into dedicated non-exported procedure ЗаполнитьУпорядоченныеЗамерыВремени() called from Прочитать(). Minor whitespace normalization across methods.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 Hop, hop, hop! The metadata hops,

No more re-scanning as reflection stops,

Cache-bound handlers, properties preserved,

TypeName-indexed, efficiency served! 📚✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'perf: Ускорена сериализация/десериализация json и формирование статистики' accurately summarizes the main objectives: performance improvements to JSON serialization/deserialization and statistics generation through caching mechanisms.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf/jason-stats

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 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

📥 Commits

Reviewing files that changed from the base of the PR and between 45c99fc and 6836b25.

📒 Files selected for processing (3)
  • src/BenchmarkOneScript/core/custom-jason/Классы/ДесериализаторJsonBench.os
  • src/BenchmarkOneScript/core/custom-jason/Классы/СериализаторJsonBench.os
  • src/BenchmarkOneScript/core/Классы/СтатистикаБенчмарка.os

@sonar-openbsl-ru-qa-bot
Copy link

Failed Quality Gate failed

  • 23.85% Duplicated Lines (%) on New Code (is greater than 3.00%)
  • 1 New Issues (is greater than 0)

Project ID: benchmark

View in SonarQube

@Stivo182 Stivo182 merged commit 713611e into main Mar 21, 2026
31 of 32 checks passed
@Stivo182 Stivo182 deleted the perf/jason-stats branch March 21, 2026 23:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant