perf(abi): AdsGetKeyCount does not recount live keys on every paint - #160
Merged
FiveTechSoft merged 1 commit intoAug 5, 2026
Merged
Conversation
Con SET DELETED ON el conteo de claves de un orden cuesta un deleted_at() por entrada, y deleted_at() lee el registro completo: sobre ARTICULO (34.595 filas, 1,6 KB por fila) son ~15 ms y ~54 MB leidos. AdsGetKeyCount es justo lo que un TXBrowse pide en CADA pintada para dimensionar la barra, asi que el browse pagaba ese precio una y otra vez por una respuesta que no habia cambiado: MantenArt sobre una compania ADT tardaba ~5 s en abrir y en reordenar. Se memoriza el conteo por indice, con la generacion de la tabla como clave. La generacion avanza en delete / recall / append / zap / pack y en el refresh que hace visible el trabajo de otro puesto, que son los unicos momentos en que el conjunto de registros vivos puede cambiar. Medido sobre la 0Y real (ADI de 22 tags): 50 llamadas pasan de 750 ms a 0 ms. Aplica igual a CDX, NTX y ADI, que compartian el mismo camino. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
FiveTechSoft
added a commit
to russimicro/OpenADS
that referenced
this pull request
Aug 5, 2026
…chSoft#164 Keep both the OPENADS_ADI_V2 gate (adi_v2_enabled) and the live-key count memoisation from FiveTechSoft#160. Register the new keycount cache test alongside the ADI v2 regression suite.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With
SET DELETED ON, counting the live entries of an order costs onedeleted_at()per index entry, anddeleted_at()reads the whole record.On a 34,595-row table with ~1.6 KB rows that is ~15 ms and ~54 MB read per
call.
AdsGetKeyCountis what aTXBrowseasks on every paint to size itsscrollbar, so the browse paid that price again and again for an answer that had
not changed.
The patch memoises the count per index, keyed by a table generation:
Table::live_gen()— bumped inmark_deleted,recall_deleted,append_record,zap,pack, and inrefresh_record_count_from_disk()(the moment another station's work becomes visible).
count_live_recnos(t, walk, owner)returns the cached number while thegeneration, the table and the walk size are unchanged.
Applies to CDX, NTX and ADI alike — they share the helper.
AdsGetKeyCount(34,595 rows, DELETED ON)Measured with a Harbour/FiveWin ERP's article table (ADT + native index bag,
22 tags) through the
rddadspath.Tests
New
abi_keycount_cache_test: on CDX and on ADI, a delete, a recall and anappend must each be visible in the very next call — the cache must never serve
a stale number.
Full suite green on this branch (1292 cases).