Title: perf(file-system): single-pass Android readTextSync that keeps line breaks by edusperoni · Pull Request #11653 · NativeScript/NativeScript · GitHub
Open Graph Title: perf(file-system): single-pass Android readTextSync that keeps line breaks by edusperoni · Pull Request #11653 · NativeScript/NativeScript
X Title: perf(file-system): single-pass Android readTextSync that keeps line breaks by edusperoni · Pull Request #11653 · NativeScript/NativeScript
Description: PR Checklist The PR title follows our guidelines: https://github.com/NativeScript/NativeScript/blob/master/tools/notes/CONTRIBUTING.md#commit-messages. There is an issue for the bug/feature this PR is for. To avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it. You have signed the CLA. All existing tests are passing: https://github.com/NativeScript/NativeScript/blob/master/tools/notes/DevelopmentWorkflow.md#unit-testing. Tests for the changes are included - https://github.com/NativeScript/NativeScript/blob/master/tools/notes/WritingUnitTests.md. What is the current behavior? Android readTextSync (file-system/file-system-access.android.ts) makes one JNI readLine() call per line and rebuilds the text from the lines. That is slow, and it also changes the content: \r\n and lone \r become \n; the trailing line break is dropped; leading blank lines are dropped. Android readText() (Async.File.readText) and iOS readTextSync()/readText() return the file unchanged, so the same file reads differently depending on the API and platform. What is the new behavior? Two commits, so either can be reverted alone. perf(file-system): read the whole file readTextSync reads the file in 64 KiB chunks into a ByteArrayOutputStream and decodes it with one toString(charset) call. This commit keeps the old output exactly, through a small _readLinesLegacy step. java.nio.file.Files isn't used: it needs API 26, and the widgets minSdk is 21. File.length() is only a size hint, so special files like /proc/* (which report a length of 0) still read correctly. The stream is now always closed. Before, it leaked whenever an error was thrown. The encoding parameter, the UTF-8 BOM removal and the onError behaviour are unchanged. fix(file-system): return the content unchanged ImportantBehaviour change. readTextSync on Android now returns the file content unchanged, like Android readText() and both iOS functions. Android-only code that compares a file's contents exactly will now see the trailing line break, and code that splits on \n keeps the \r of CRLF files. The UTF-8 BOM is still removed. test_FileReadTextKeepsLineBreaks in apps/automated covers this. It writes CRLF, CR and LF content larger than one read chunk and checks that readTextSync() and readText() both return it unchanged. Verification apps/automated on an Android emulator (API 36, @nativescript/android 9.1.1) passes. A temporary benchmark module (not committed): readTextSync() of a 1 MiB file with 16,645 CRLF lines went from ~12 ms to 2–3.5 ms. It also checked that the BOM is still stripped, onError is still called with undefined returned for a missing file, and /proc/self/status still reads. Split out of #11636.
Open Graph Description: PR Checklist The PR title follows our guidelines: https://github.com/NativeScript/NativeScript/blob/master/tools/notes/CONTRIBUTING.md#commit-messages. There is an issue for the bug/feature this...
X Description: PR Checklist The PR title follows our guidelines: https://github.com/NativeScript/NativeScript/blob/master/tools/notes/CONTRIBUTING.md#commit-messages. There is an issue for the bug/feature this...
Opengraph URL: https://github.com/NativeScript/NativeScript/pull/11653
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:fef4cd06-56fd-9b54-cd50-3134075f453c |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | C59A:882E2:175FC66:1EC1405:6B013035 |
| html-safe-nonce | 678039800d016513cdba82af0329a5d985fb601bac94f6f6d842e97ceeb2a216 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNTlBOjg4MkUyOjE3NUZDNjY6MUVDMTQwNTo2QjAxMzAzNSIsInZpc2l0b3JfaWQiOiI0NDg5MzQ5Njk2NDc2NzUzOTczIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | a1d092d3ff362cb6f573fffa47e1b5910839a6772100a74703a836cdc7ae5d6f |
| hovercard-subject-tag | pull_request:5416995232 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/NativeScript/NativeScript/pull/11653/files |
| twitter:image | https://avatars.githubusercontent.com/u/4061767?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/4061767?s=400&v=4 |
| og:image:alt | PR Checklist The PR title follows our guidelines: https://github.com/NativeScript/NativeScript/blob/master/tools/notes/CONTRIBUTING.md#commit-messages. There is an issue for the bug/feature this... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/NativeScript/NativeScript git https://github.com/NativeScript/NativeScript.git |
| octolytics-dimension-user_id | 7392261 |
| octolytics-dimension-user_login | NativeScript |
| octolytics-dimension-repository_id | 31492490 |
| octolytics-dimension-repository_nwo | NativeScript/NativeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 31492490 |
| octolytics-dimension-repository_network_root_nwo | NativeScript/NativeScript |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width