Skip to content

Speed up the rcg parser and update the bundled simdjson to 5.1.1 - #123

Merged
hidehisaakiyama merged 10 commits into
developfrom
feature/rcg-parser-speedup
Nov 25, 2026
Merged

hidehisaakiyama merged 10 commits into
developfrom
feature/rcg-parser-speedup

Conversation

@hidehisaakiyama

@hidehisaakiyama hidehisaakiyama commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Summary

Loading game logs (rcg) with the rcg parser of librcsc is now 3.5 to 4.7 times as fast,
following the method of rcssmonitor (rcssmonitor PR #65):
read the whole file into memory, parse it there, and parse the lines in parallel.
The bundled simdjson is updated from 3.8.0 to 5.1.1, which removes the 9 warnings of GCC 15.
The parsers also read broken and new game logs more robustly, and several bugs are fixed.

Plan: docs/plan/2026-11-24-02_rcg-parser-speedup.md (7 stages, all done).

Speed

The time to load a game log by the tools (best of 5, CMake Release, 8 threads):

Game log Size (decompressed) Before After (libdeflate) After (zlib only)
JSON 53.6 MB 205.9 ms 43.9 ms 72.4 ms
text v5 28.7 MB 123.6 ms 35.8 ms 60.8 ms
text v6 22.3 MB 90.5 ms 26.1 ms 43.8 ms

soccerwindow2, unchanged and rebuilt with this librcsc, parses the JSON game log in 113 ms instead of 235 ms.
It reads the file through rcsc::gzifstream; switching it to rcsc::gzread_file() makes it 54 ms
(to be done in soccerwindow2; recorded in docs/todo.md).

Changes

  • simdjson 5.1.1: the bundled simdjson is updated (the same files as rcssmonitor).
    The old JSON parser parser_json.{h,cpp}, which neither build used, is moved to obsolete/rcg,
    and the bundled nlohmann/json, which only it used, is deleted.
  • Parsing in memory:
    • New rcsc::gzread_file() (rcsc/gz/gzread_file.h) reads a whole (gzip) file into memory.
    • New rcsc::rcg::Parser::create( data, size ) and Parser::parse( data, size, handler ).
    • Parser::parse( filepath, handler ) reads gzip files, and the derived classes no longer hide it.
    • parse( std::istream &, ... ) also reads the stream into memory first, so the existing callers get faster.
    • A JSON game log of one record per line is parsed record by record in place; a log whose last ] is missing can be read.
  • Parallel parsing: the lines of a large game log are parsed by several threads.
    The handler is always called in the calling thread, in the order of the lines.
    New Parser::setMaxThreads( n ) and Parser::maxThreads() (default: the smaller of the hardware threads and 8; 1 disables it).
  • libdeflate (optional): if it is found, gzread_file() decompresses gzip files with libdeflate (about twice as fast as zlib).
    -DENABLE_LIBDEFLATE=OFF (CMake) and --without-libdeflate (Autotools) disable it.
  • Robustness and bug fixes:
    • Text: a buffer overflow by a long record name, a write outside the array by the player number 0,
      broken shows, an exception by a broken header, team graphics longer than 15 characters, and more.
    • JSON: the server version and the timestamp are passed to the handler; the view quality is stored correctly
      (the JSON written by the tools had "vq":"l" for all the players); the players are placed by side and number;
      unknown records and keys are skipped.
    • The tools: rcgreverse, rcgrenameteam and rcgverconv write the server version and the timestamp of a JSON game log;
      rcg2csv and rcgvalidator accept JSON game logs explicitly; rcgresultprinter no longer uses a temporary file and
      prints the right dates; rcgversion recognizes the version 6.
  • Tools for the development: src/rcg_parser_bench (not installed) and test/compare_rcg_output.sh.

Compatibility

  • The source API is compatible: soccerwindow2 builds without changes.
  • The ABI is changed (new virtual functions of Parser, Handler::handleTimestamp() is now virtual).
    Rebuild the programs built with librcsc of the develop branch. The SOVERSION is not changed.
  • The handler's return values no longer stop the parsing (the JSON parser stopped before),
    and a line that cannot be parsed is skipped with a message (the parsing stopped before).
  • librcsc is linked with the thread library, and with libdeflate if it is used.

Tests

  • New unit tests (CppUnit, CMake and Autotools): run_test_rcg_parser (35 cases, on the first records of real game logs),
    run_test_rcg_line_parser (8), run_test_gzread_file (7).
  • CI: all jobs pass with no compiler warnings on Ubuntu 24.04 (GCC 13) and 26.04 (GCC 15).
    The CMake jobs use libdeflate, and the Autotools jobs use zlib only.
  • Checked locally: ThreadSanitizer, AddressSanitizer and UBSan; builds without zlib and without libdeflate;
    the outputs of rcgverconv for 7 real game logs are the same as before except the fixed view quality.
  • soccerwindow2 (develop) builds with this librcsc, its tests pass, and it shows the game logs correctly.

…eedup stage 1)

RCG パーサの高速化の計画書を追加し、その段階 1 として、計測と回帰テストの土台を作った。
- src/rcg_parser_bench: rcg の読み込みの時間を計る開発用のプログラム (インストールしない)。
  初めに、読み込んだ librcsc の場所を出す。
- run_test_rcg_parser: 実際のログの先頭 (rcsc/rcg/test_data) で、テキスト (v5・v6) と
  JSON のパーサを確かめる単体テスト (CppUnit)。
- test/compare_rcg_output.sh: 2 つのビルドの rcgverconv の出力を比べ、同じデータを読むことを
  確かめるスクリプト。
- docs/build.md に、テストとツールの使い方を書いた。
計画書: docs/plan/2026-11-24-02_rcg-parser-speedup.md

Add the plan of the RCG parser speedup, and, as its stage 1, the base for the
measurements and the regression tests.
- src/rcg_parser_bench: a development program (not installed) that measures the
  time to load game logs. It prints the path of the loaded librcsc first.
- run_test_rcg_parser: a unit test (CppUnit) of the text (v5, v6) and JSON parsers
  on the first records of real game logs (rcsc/rcg/test_data).
- test/compare_rcg_output.sh: a script that compares the outputs of rcgverconv of
  two builds, to check that they read the same data.
- docs/build.md describes the test and the tools.
Plan: docs/plan/2026-11-24-02_rcg-parser-speedup.md
…G parser speedup stage 2)

同梱の simdjson を 3.8.0 から 5.1.1 に更新した。GCC 15 で simdjson.cpp に出ていた警告
(-Wtemplate-id-cdtor、9 件) がなくなる。3.8.0 に当てていた GCC 15 の修正は 5.1.1 に入っている。
- parser_simdjson.cpp: チームのグラフィックの文字列を、ほかの値と同じく読むようにした
  (5.x では get_string( std::string & ) の結果を使わないと警告になる)。
- どちらのビルドにも入っていなかった古い JSON パーサ (parser_json.{h,cpp}) を obsolete/rcg に移し、
  それだけが使っていた nlohmann/json.hpp を削除した。
- run_test_rcg_parser に JSON のチームのグラフィックのテストを足した。
- リリースノートに、段階 1 と段階 2 の変更を書いた。
計画書: docs/plan/2026-11-24-02_rcg-parser-speedup.md

Update the bundled simdjson from 3.8.0 to 5.1.1. The 9 warnings of GCC 15 in
simdjson.cpp (-Wtemplate-id-cdtor) are gone, and 5.1.1 has the fix for GCC 15
that was applied to 3.8.0.
- parser_simdjson.cpp: read the strings of a team graphic as the other values
  are read (get_string( std::string & ) warns in 5.x when its result is unused).
- Move the old JSON parser (parser_json.{h,cpp}), which neither build used, to
  obsolete/rcg, and delete nlohmann/json.hpp, which only it used.
- Add a test of a JSON team graphic to run_test_rcg_parser.
- Describe the changes of stages 1 and 2 in the release notes.
Plan: docs/plan/2026-11-24-02_rcg-parser-speedup.md
…he plan

RCG パーサの高速化の計画書を更新した。
- 段階 2 (e778865) の CI の結果を記録した。GCC 15 の警告 9 件は解消した。
- ユーザの決定 D7: ファイルをメモリに読む関数は rcsc/gz に置く。
- 作業の場所を移すため、段階 3 の前で中断した。再開の手順を書いた。

Update the plan of the RCG parser speedup.
- Record the CI result of stage 2 (e778865): the 9 warnings of GCC 15 are gone.
- The user's decision D7: the function that reads a file into memory goes in rcsc/gz.
- The work stops before stage 3 to move to another place; describe how to resume.
…edup stage 3)

rcg を、ファイル全体をメモリに読んでから解析するようにした。
- rcsc::gzread_file() (rcsc/gz/gzread_file.h): ファイル全体をメモリに読む。gzip は zlib で展開する。
- Parser::create( data, size ) と Parser::parse( data, size, handler ) を加えた。
  parse( filepath ) は gzread_file() で読むため、gzip を読める。派生クラスで隠れなくなった。
- ParserV4 と ParserSimdJSON はメモリの上で解析する。parse( std::istream & ) もメモリに読んでから解析する。
- JSON は、1 行 1 レコードのログを行ごとにバッファの上で解析する。最後の "]" がないログも読める。
  ほかの書き方のログは、文書全体として解析する。
- JSON のパーサも、handleLogVersion() が false なら読み込みをやめる。
- ツールを gzread_file() とメモリの経路に替えた。rcgresultprinter は一時ファイルを使わなくなった。
- rcg2csv と rcgvalidator が JSON を受け付けるようにした。rcgresultprinter の日時のずれを直した。
- テスト: run_test_rcg_parser を増やし、run_test_gzread_file を足した。
計画書: docs/plan/2026-11-24-02_rcg-parser-speedup.md

Read the whole game log into memory and parse it there.
- rcsc::gzread_file() (rcsc/gz/gzread_file.h) reads a whole file into memory,
  decompressing a gzip file with zlib.
- Add Parser::create( data, size ) and Parser::parse( data, size, handler ).
  parse( filepath ) reads the file by gzread_file(), so it reads gzip files,
  and the derived classes no longer hide it.
- ParserV4 and ParserSimdJSON parse the data in memory. parse( std::istream & )
  also reads the stream into memory first.
- A JSON log of one record per line is parsed line by line in the buffer, so a
  log whose last "]" is missing can be read. Other JSON logs are parsed as one
  document.
- The JSON parser stops if handleLogVersion() returns false.
- The tools use gzread_file() and parse in memory. rcgresultprinter no longer
  uses a temporary file.
- rcg2csv and rcgvalidator accept JSON logs. Fix the dates of rcgresultprinter,
  which could be one hour off.
- Tests: extend run_test_rcg_parser and add run_test_gzread_file.
Plan: docs/plan/2026-11-24-02_rcg-parser-speedup.md
…ork in docs/todo.md

- run_test_rcg_parser: GCC 15 の -Wdangling-reference の警告 (誤検出) が出た所を書き換えた。
  gzip のテストのデータを作る関数を 2 回呼ぶようにした。
- docs/todo.md: RCG パーサの高速化の計画で対象外にしたり見送ったりした作業を記録した。
- 計画書に、段階 3 の CI の結果を記録した。
計画書: docs/plan/2026-11-24-02_rcg-parser-speedup.md

- run_test_rcg_parser: avoid the warning -Wdangling-reference of GCC 15
  (a false positive), by calling a function that writes the gzip test data twice.
- docs/todo.md: record the work that the plan of the RCG parser speedup leaves
  out or postpones.
- Record the CI result of stage 3 in the plan.
Plan: docs/plan/2026-11-24-02_rcg-parser-speedup.md
rcg の行を、複数のスレッドで並列に解析するようにした (rcssmonitor と同じ方式)。
- 多くの行は、連続したブロックに分けて std::thread で解析し、記録したものを元の順にハンドラへ渡す。
  ハンドラは、parse() を呼んだスレッドだけから呼ばれる。
- Parser::setMaxThreads() と Parser::maxThreads(): スレッドの数の上限。
  既定はハードウェアのスレッドの数と 8 の小さい方。1 で並列にしない。
- ハンドラの戻り値で読み込みを止めない (JSON も)。1 スレッドのときも記録してから渡し、
  スレッドの数によらずハンドラの扱いを同じにした。
- 解析できない行は飛ばして続け、最後にまとめて報告する。
- Handler::handleTimestamp() を仮想にした。librcsc をスレッドのライブラリにリンクする。
- ベンチマークに -t (スレッドの数の上限) を加えた。
- テスト: run_test_rcg_line_parser を足し、run_test_rcg_parser に大きなログのテストを足した。
計画書: docs/plan/2026-11-24-02_rcg-parser-speedup.md

Parse the lines of a game log in parallel, as rcssmonitor does.
- Many lines are split into consecutive blocks, parsed by std::thread, and the
  records are passed to the handler in the order of the lines. The handler is
  called only in the thread that calls parse().
- Parser::setMaxThreads() and Parser::maxThreads(): the upper limit of the
  number of the threads. The default is the smaller of the number of the
  hardware threads and 8. 1 disables the parallel parsing.
- The return values of the handler no longer stop the parsing (also for JSON).
  With one thread, the lines are also recorded before they are passed, so the
  handler is used in the same way whatever the number of the threads.
- A line that cannot be parsed is skipped and reported at the end.
- Handler::handleTimestamp() is now virtual. librcsc is linked with the thread
  library.
- Add -t (the upper limit of the threads) to the benchmark.
- Tests: add run_test_rcg_line_parser, and tests of large logs to
  run_test_rcg_parser.
Plan: docs/plan/2026-11-24-02_rcg-parser-speedup.md
…dup stage 5)

rcsc::gzread_file() は、libdeflate があれば gzip を libdeflate で展開する (zlib のおよそ 2 倍の速さ)。
- 壊れた gzip (途中で切れたファイルなど) は、zlib で読み直して切れた所まで読む。
- 任意の依存とした。CMake は ENABLE_LIBDEFLATE (既定は ON)、Autotools は --with-libdeflate
  (既定は見つかれば使う。--without-libdeflate で使わない)。
- libdeflate は librcsc.so にだけリンクする。
- CI: CMake のジョブにだけ libdeflate-dev を入れ、Autotools のジョブは zlib だけでビルドする。
- README.md、docs/build.md、リリースノートに書いた。
計画書: docs/plan/2026-11-24-02_rcg-parser-speedup.md

rcsc::gzread_file() decompresses gzip files with libdeflate if it is found,
which is about twice as fast as zlib.
- A broken gzip file (e.g. one that ends in the middle) is read again by zlib
  up to where it is broken.
- libdeflate is an optional dependency: ENABLE_LIBDEFLATE of CMake (ON by
  default), and --with-libdeflate of Autotools (used if found by default;
  --without-libdeflate disables it).
- Only librcsc.so is linked with libdeflate.
- CI: the CMake jobs install libdeflate-dev, and the Autotools jobs build
  librcsc with zlib only.
- Describe it in README.md, docs/build.md and the release notes.
Plan: docs/plan/2026-11-24-02_rcg-parser-speedup.md
…ser speedup stage 6)

rcg のパーサの、壊れたログや新しいログの読み込みの不具合を直した。
- テキスト: 長い記録の名前のバッファのあふれ、背番号 0 の配列の外への書き込み、壊れた時刻とボール、
  壊れたヘッダの例外、空行、知らない記録 (1 度だけ報告して飛ばす)、15 文字を超えるチームのグラフィック、
  チームの行の null の名前。
- JSON: version と timestamp をハンドラに渡す。vq を 'h'・'l' で入れる (ツールが書いた JSON では
  すべてのプレイヤーが "vq":"l" になっていた)。プレイヤーを side と背番号の位置に置き、省かれうる
  フィールドは既定の値にする。知らない記録とキーは飛ばす。ライブの parseData() は例外を出さない。
- rcgreverse・rcgrenameteam・rcgverconv は、JSON のログの version と timestamp を出力に書く。
- rcgversion は v6 を判別する。
- ボールの高さは読まない (サーバの形式が決まってから。docs/todo.md)。
- テスト: run_test_rcg_parser に、それぞれの不具合のテストを足した。
計画書: docs/plan/2026-11-24-02_rcg-parser-speedup.md

Fix the problems of the rcg parsers in reading broken or new game logs.
- Text: the buffer overflow by a long record name, the write outside the array
  by the player number 0, broken times and balls, the exception by a broken
  header, empty lines, unknown records (skipped and reported once), team
  graphics longer than 15 characters, and the name null in a team line.
- JSON: pass the version and the timestamp to the handler. Store vq as 'h' or
  'l' (the JSON written by the tools had "vq":"l" for all the players). Place
  the players by side and number, and keep the default values of the fields
  that the server may omit. Skip unknown records and keys. parseData() for a
  live connection does not throw.
- rcgreverse, rcgrenameteam and rcgverconv write the version and the timestamp
  of a JSON game log to the output.
- rcgversion recognizes the version 6.
- The height of the ball is not read (until the server's format is fixed;
  docs/todo.md).
- Tests: add the tests of the problems to run_test_rcg_parser.
Plan: docs/plan/2026-11-24-02_rcg-parser-speedup.md
…arser speedup stage 7)

RCG パーサの高速化の段階 7 (仕上げ) の結果を、計画書に記録した。
- 最終の計測: CMake・Autotools と、zlib だけ・libdeflate の 4 つの組み合わせ。
- 全体の比較: 手元の 7 つのログの 14 の変換で、違いは JSON のログの vq の修正による所だけ。
- soccerwindow2 を変えずに新しい librcsc でビルドでき、テストが通り、ユーザが画面で確かめた。
- soccerwindow2 が rcssmonitor より遅い理由を調べた: gzifstream を通した展開。gzread_file() に
  替えると JSON で約 115 → 54 ms になる。soccerwindow2 の切り替えを docs/todo.md に書き足した。
計画書: docs/plan/2026-11-24-02_rcg-parser-speedup.md

Record the results of stage 7 (finishing) of the RCG parser speedup in the plan.
- The final measurements with CMake and Autotools, with zlib only and with
  libdeflate.
- The comparison of 14 conversions of 7 game logs: the only differences are the
  fixed view quality of the JSON game log.
- soccerwindow2 builds with the new librcsc without changes, its tests pass, and
  the user checked it on the screen.
- Why soccerwindow2 is slower than rcssmonitor: the decompression through
  gzifstream. Reading the file by gzread_file() makes it about 115 -> 54 ms for
  the JSON game log. Add the numbers to the soccerwindow2 item of docs/todo.md.
Plan: docs/plan/2026-11-24-02_rcg-parser-speedup.md
@hidehisaakiyama
hidehisaakiyama marked this pull request as ready for review November 25, 2026 10:26
… the plan

RCG パーサの高速化の計画書に、develop への取り込みの記録を書いた。
- 段階 7 (3e87052) の CI の結果を記録した。
- PR #123 を Squash Merge で develop に取り込む。
- 計画の結果 (ツールの読み込みは 3.5〜4.7 倍の速さ、simdjson 5.1.1、不具合 B1〜B14 の修正) と、
  この後の作業 (soccerwindow2 の切り替え、docs/todo.md) をまとめた。
計画書: docs/plan/2026-11-24-02_rcg-parser-speedup.md

Record the merge of the RCG parser speedup into develop in the plan.
- Record the CI result of stage 7 (3e87052).
- PR #123 is merged into develop by Squash Merge.
- Summarize the results (the tools load game logs 3.5 to 4.7 times as fast,
  simdjson 5.1.1, the fixes of B1 to B14) and the next work (switching
  soccerwindow2; docs/todo.md).
Plan: docs/plan/2026-11-24-02_rcg-parser-speedup.md
@hidehisaakiyama
hidehisaakiyama merged commit 4291244 into develop Nov 25, 2026
5 checks passed
@hidehisaakiyama
hidehisaakiyama deleted the feature/rcg-parser-speedup branch November 25, 2026 10:37
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