Conversation
ToLLA built a projected coordinate system and a coordinate transformation for every point. Cache the inverse transform per signed zone instead. Zones outside 1-60 are converted without caching so that zone numbers typed into the coordinate editor cannot grow the cache. Results are bit-identical to the uncached path. Grid.CreateGrid on a 20,519-point survey drops from 49 ms to 5 ms.
GetMessageInfo scanned the 350-entry message table linearly, two to three times per parsed packet, so the cost grew with the message id (11 ns for HEARTBEAT, 489 ns for ESC_TELEMETRY_1_TO_4). Build a dictionary per table instance and rebuild it when the table is replaced, as NvModemMavlinkDialect.Register does at runtime. First match, unknown-id and null-array behavior are unchanged. Lookups are now about 14 ns for every id. Parsing a tlog of ArduPilot-specific messages is about 1.9x faster; a tlog of common low-id messages about 7% faster.
Every metadata lookup walked the XML documents linearly: a LINQ scan of all param elements in up to six pdef documents, then XContainer.Element over thousands of siblings in the legacy file. Answers that are empty, the common case for Range, Increment, Bitmask and RebootRequired, were never cached, so filling a parameter table cost about 1.4 s every time, partly on the UI thread. Index each pdef document by name attribute, keeping document order so scoped and unscoped entries resolve exactly as before, and index the legacy document by vehicle and parameter element name. Indexes are tied to their document: a replaced document gets a new index, and an edited pdef document drops its index. 1,200 parameters x 8 keys: 1,714 ms -> 27 ms cold, 1,371 ms -> 13 ms warm, with identical answers.
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.
Three small lookup fixes, one commit each, smallest first. Each replaces linear or per-call work with a cached or indexed lookup and returns the same answers as before, verified by tests that compare the new code against a copy of the old lookup.
1.
utmpos.ToLLAinverse transform cache (ExtLibs/Utilities/utmpos.cs)ToLLAbuilt a projected coordinate system and a transformation for every point;Grid.CreateGridcalls it once per waypoint on every survey slider change, on the UI thread. The inverse transform is now cached per signed zone, mirroring the forward cache inPointLatLngAlt. Zones outside the real UTM range are converted without caching, so values typed into the coordinate editor cannot grow the cache.2.
GetMessageInfodictionary lookup (ExtLibs/Mavlink/MavlinkUtil.cs)GetMessageInfoscanned the 350-entry message table linearly, two to three times per parsed packet, so the cost grew with the message id. The globalMAVLINK_MESSAGE_INFOStable is now indexed in a dictionary that is rebuilt when the table is replaced (NvModemMavlinkDialect.Registerand plugins do this at runtime); any other array keeps the linear scan. First-match, unknown-id and null-array behavior are unchanged.Residual: an entry edited in place (
MAVLINK_MESSAGE_INFOS[i] = ...) is not seen until the array is replaced. Nothing in this repo or in upstream's example plugin does that.3. Parameter metadata document indexes (
ExtLibs/Utilities/ParameterMetaDataRepositoryAPMpdef.cs,ParameterMetaDataRepositoryAPM.cs)Every metadata lookup walked the XML linearly: all
paramelements of up to three pdef sources (local overlay plus downloaded document each), thenXContainer.Elementover thousands of siblings in the legacy file. Empty answers, the common case for Range, Increment, Bitmask and RebootRequired, are never cached, so filling a parameter table cost about 1.4 s every time, partly on the UI thread.Each pdef document is now indexed by
nameattribute, keeping document order so scoped and unscoped entries resolve exactly as before; the legacy document is indexed by vehicle and parameter element name. An index is tied to its document and rebuilt when the document is replaced or edited. Empty answers are still not cached, because the metadata downloads asynchronously after first use.Pre-existing and left alone: a vehicle type with no
.apm.pdef.xmlon disk still costs aFile.Existsper lookup, and_parameterMetaDataXMLis an unsynchronized dictionary written from a task continuation.Measurements
Release build, .NET 10, Windows x64.
utmpos.ToLLAcallsGrid.CreateGrid, 20,519 pointsGetMessageInfocalls, mixed idsVerification
UtmposTransformCacheTests(11),MavlinkMessageInfoLookupTests(8),ParameterMetadataIndexTests(10), over the packaged metadata files and synthetic documents that cover the ordering rules.ParameterMetaDataRepository(6,836 names, 11 keys, 6 vehicle types including the SITL, AP_Periph and legacy fallbacks) are byte-identical between old and new code.master.