Swift: Parsing with regular expressions is incredibly slow
| Originator: | nimayousefi1 | ||
| Number: | rdar://20248576 | Date Originated: | 20-Mar-2015 10:56 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode Version 6.3 (6D543q) |
| Classification: | Performance | Reproducible: | Always |
Summary: Attached is a sample project that uses regular expressions to scan the contents of a document. Regular expressions are used to parse the structure Document = Paragraph Paragraph = Line LineBreak Line = .+ LineBreak The project includes the Objective-C and Swift versions of this code, and is a line-by-line conversion. It also has performance tests for each. The Objective-C takes ~ 0.081 s on my machine to parse the entire document. I have been unable to get the The Swift test to finish because it takes many, many times longer. If I only parse the 1st paragraph of the document with Swift, though, it takes ~ 0.2 s to run (instructions to do this in the code). The performance difference is shocking. Changing the Swift compiler optimization to -O (fastest) does not improve the situation. Steps to Reproduce: 1. Open the attached project. 2. Cmd-U to run the tests Expected Results: The ObjC tests and the Swift tests should finish in roughly the same amount of time. Actual Results: The Swift code runs dramatically slower. It's not even close. Version: Xcode Version 6.3 (6D543q) Notes: This is happening on my MacBookPro11,1 (2.4 Ghz i5, 8 GB RAM), in case it's machine specific issue. * The sample project referred to here is available at https://github.com/nyousefi/SwiftRegexSlowness
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!