Title: Performance improvement of IfcParse tokenizer by stgatilov · Pull Request #82 · IfcOpenShell/IfcOpenShell · GitHub
Open Graph Title: Performance improvement of IfcParse tokenizer by stgatilov · Pull Request #82 · IfcOpenShell/IfcOpenShell
X Title: Performance improvement of IfcParse tokenizer by stgatilov · Pull Request #82 · IfcOpenShell/IfcOpenShell
Description: In my opinion, most of the performance issues in IfcParse are due to too many dynamic memory allocations. This PR is dedicated to removing memory allocations in tokenization process, at least for numbers and operators. As a result, opening a 47Mb file in our IfcParse-based project now takes 9.5 seconds instead of 12.5 seconds. According to MSVC profiler, samples count of IfcParse.dll has reduced from 3600 to 2600. Built with MSVC2013 x64 with additional optimizations enabled. In the new tokenization system, most of the information for each token is determined at the moment it is created, and it is saved within the Token struct itself. In particular: startPos - index of first char in token (was saved before). endPos - index of the after-the-last char of token (I thought it would be useful, but it is not actually used). type - operator/keyword/integer/bool/whatever. value - only for some types of tokens, stored in union. For simple tokens, their values are determined on creation without any memory allocations. This allows to avoid costly creation of std::string-s in IfcSpfLexer::TokenString function. There are several points I would like to discuss about these changes: (1) According to STEP specification, EOL chars may appear in any tokens. So breaking a real number into two lines is considered a correct STEP. This is rather unpleasant for tokenization, because it is not possible to parse numbers with standard libraries "in-place" (unless all EOLs are removed even before tokenization). In order to support such weird tokens, I copy each token into a 64-byte buffer on stack, removing all EOL in process (see function RemoveTokenSeparators). This allows to avoid dynamic allocation, but limits length of any integer or real number to 63 characters. I wonder if it is really a problem and if anyone knows a way to fix it (without dynamic allocation). For example, the following valid numbers would screw tokenization process in the PR: integer: 00000...[repeat 70 times]...0000078 real: 14.1039...[write 70 digits]...23569 (2) IfcParse library lacks an assert macro. Throwing exception is the right thing to do on ill-formatted inputs. But sometimes it is desirable to check for conditions which must be true by construction, in order to simplify debugging process. And throwing exception in a small getter function is a waste of program time and space. See functions asInt, asFloat and other for example.
Open Graph Description: In my opinion, most of the performance issues in IfcParse are due to too many dynamic memory allocations. This PR is dedicated to removing memory allocations in tokenization process, at least for n...
X Description: In my opinion, most of the performance issues in IfcParse are due to too many dynamic memory allocations. This PR is dedicated to removing memory allocations in tokenization process, at least for n...
Opengraph URL: https://github.com/IfcOpenShell/IfcOpenShell/pull/82
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
| 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:83cc1989-fd86-ddd9-3d72-421819279df1 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | B7EE:EE4AB:A89732:E56D4E:6B048380 |
| html-safe-nonce | ff8ed200d0e23b4a934d8727411d855312fde9ed02d90c9af99b1a8100708de9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCN0VFOkVFNEFCOkE4OTczMjpFNTZENEU6NkIwNDgzODAiLCJ2aXNpdG9yX2lkIjoiNzM0MTYwOTU4MDkxNzIzNjQ4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 6598ecb7c97dfa7aa5ee3781e6a14c5567fb9db5431dac7d4203fc6c58fdbf4d |
| hovercard-subject-tag | pull_request:72310139 |
| 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/IfcOpenShell/IfcOpenShell/pull/82/files |
| twitter:image | https://avatars.githubusercontent.com/u/13484213?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/13484213?s=400&v=4 |
| og:image:alt | In my opinion, most of the performance issues in IfcParse are due to too many dynamic memory allocations. This PR is dedicated to removing memory allocations in tokenization process, at least for n... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 1d5c152376e38b7d2e37f3d5179be29a73bee93b85110da28a4eebe1159cdc70 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/IfcOpenShell/IfcOpenShell git https://github.com/IfcOpenShell/IfcOpenShell.git |
| octolytics-dimension-user_id | 13692563 |
| octolytics-dimension-user_login | IfcOpenShell |
| octolytics-dimension-repository_id | 40473201 |
| octolytics-dimension-repository_nwo | IfcOpenShell/IfcOpenShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 40473201 |
| octolytics-dimension-repository_network_root_nwo | IfcOpenShell/IfcOpenShell |
| 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 | f5017e8ff4ea25a8011fcf0f2a0e430c60dc86c8 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | no-cache |
Viewport: width=device-width