Azure: Reduce allocations in ADLSLocation URI parsing#16788
Open
wombatu-kun wants to merge 1 commit into
Open
Conversation
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
ADLSLocation is constructed once per FileIO operation (newInputFile, newOutputFile, deleteFile, listPrefix, deletePrefix all call new ADLSLocation(path)), so its constructor is on the metadata path of every scan and commit.
The constructor split the authority with String.split("@", -1) and then extracted the storage account with host.split("\.", -1)[0]. The second split is the wasteful part: to read the account it materializes every dotted segment of the host (account.dfs.core.windows.net produces 5 strings plus the backing array) and then discards all but the first. This change parses the same fields with indexOf/substring, dropping the intermediate ArrayList, array, and unused substrings. The regex match is kept for scheme validation, so all parsing and error behavior is unchanged.
Behavior is identical for every valid abfs/abfss/wasb/wasbs URI (zero or one @, host with or without dots); only pathological multi-@ authorities, which are already invalid, would differ. The storage-account extraction now guards the no-dot case (indexOf returns -1) explicitly, which a new test pins.
Local JMH results (AverageTime, 5x1s warmup, 5x1s measurement, 1 fork, gc profiler; gc.alloc.rate.norm is deterministic):
That is roughly -40% allocation and about 1.6x faster per parse. The benchmark was run locally and is not included (the azure module has no JMH source set).
Tests: TestADLSLocation already covers the abfs/abfss/wasb/wasbs, with/without container, no-path and host-extraction cases; added testHostWithoutDot to pin the no-dot storage-account branch.