summaryrefslogtreecommitdiff
path: root/src/lib/corelib/language/scriptimporter.cpp
Commit message (Collapse)AuthorAgeFilesLines
* ScriptEngine: Make import functionality exception safeChristian Kandeler2023-04-281-2/+3
| | | | | | Fixes: QBS-1730 Change-Id: I83324b7d859412580213dc4eb9f1f60e0f9063f2 Reviewed-by: Ivan Komissarov <ABBAPOH@gmail.com>
* Switch JavaScript back-endChristian Kandeler2023-02-071-14/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Newer clang versions seem to expose serious bugs in QtScript, whose complexity makes it difficult to track them down. We therefore switch to the more light-weight QuickJS, which offers all the features we need (most notably property access interception), as well as good performance. To save some porting effort, we removed the long-deprecated loadFile() and loadExtension() functions. During the porting procedure, we noticed and fixed thread safety issues in artifact access from JS commands. We consider this change important enough to bump the major version, so the next release will be 2.0. Detailed benchmarking data is below. In summary, we see a modest speed- up at the cost of a similarly modest increase in memory consumption (with the exception of project resolving on macOS, which has become a bit slower). Importantly, the increase does not rise with project size, as the comparison of qbs vs Qt Creator shows. Output of qbs_benchmarker on Linux with qbs as test project: ========== Performance data for Resolving ========== Old instruction count: 12870602895 New instruction count: 11923459780 Relative change: -8 % Old peak memory usage: 61775848 Bytes New peak memory usage: 67583424 Bytes Relative change: +9 % ========== Performance data for Rule Execution ========== Old instruction count: 4074062223 New instruction count: 3887473574 Relative change: -5 % Old peak memory usage: 35123704 Bytes New peak memory usage: 38398392 Bytes Relative change: +9 % ========== Performance data for Null Build ========== Old instruction count: 1104417596 New instruction count: 1011033948 Relative change: -9 % Old peak memory usage: 24461824 Bytes New peak memory usage: 25325920 Bytes Relative change: +3 % Output of qbs_benchmarker on Linux with Qt Creator as test project: ========== Performance data for Resolving ========== Old instruction count: 67166450352 New instruction count: 60772791018 Relative change: -10 % Old peak memory usage: 327011616 Bytes New peak memory usage: 343724176 Bytes Relative change: +5 % ========== Performance data for Rule Execution ========== Old instruction count: 71684351183 New instruction count: 67051936965 Relative change: -7 % Old peak memory usage: 374913688 Bytes New peak memory usage: 387790992 Bytes Relative change: +3 % ========== Performance data for Null Build ========== Old instruction count: 8383156078 New instruction count: 7930705668 Relative change: -6 % Old peak memory usage: 180468360 Bytes New peak memory usage: 182490384 Bytes Relative change: +1 % Real-world data building Qt Creator (using qbs --log-time, several runs, removing outliers): macOS: Resolving: 43s -> 47s Rule execution: 17s -> 14s Windows: Resolving: 18s -> 16s Rule execution: 22s -> 17s Fixes: QBS-913 Fixes: QBS-1103 Fixes: QBS-1126 Fixes: QBS-1227 Fixes: QBS-1684 Change-Id: Ie5088155026e85bbd1e303f1c67addb15810a3cb Reviewed-by: Ivan Komissarov <ABBAPOH@gmail.com> Reviewed-by: Orgad Shaneh <orgads@gmail.com>
* qt6: replace some QStringRefs with QStringViewsIvan Komissarov2020-11-091-4/+5
| | | | | | | | | QStringRef does not exist anymore. Qml parser is not ported yet. Change-Id: Ifb99a529b69c0085363031e852ffd7576f1d93be Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
* Fix uninitialized variablesIvan Komissarov2019-05-021-2/+2
| | | | | | | | | This fixes most of clang analyzer warnings about uninitialized variables in ctors Change-Id: I879c785594307ed3fe7140588338a6b2a1e4db65 Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
* JS imports: Cache also the results of "require"Christian Kandeler2018-06-121-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, we only did this when the import statement was used. ========== Performance data for Resolving ========== Old instruction count: 4222084293 New instruction count: 4059138786 Relative change: -4 % Old peak memory usage: 31448616 Bytes New peak memory usage: 31345168 Bytes Relative change: -1 % ========== Performance data for Rule Execution ========== Old instruction count: 2801901530 New instruction count: 2713710190 Relative change: -4 % Old peak memory usage: 20535920 Bytes New peak memory usage: 20527264 Bytes Relative change: -1 % ========== Performance data for Null Build ========== Old instruction count: 602407594 New instruction count: 550459348 Relative change: -9 % Old peak memory usage: 15631832 Bytes New peak memory usage: 15631752 Bytes Relative change: -1 % Change-Id: I4c7ff9f83799a0da9b2e4e67c5b946bd02f199c3 Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
* Remove duplicated script error handling codeJoerg Bornemann2018-01-101-15/+2
| | | | | | | | | Add throwOnEvaluationError to evaluator.h. That function takes a function argument that provides a fallback error location in case the location cannot be extracted from the script error itself. Change-Id: I4ad5d87f5876b9025e7ab4c65285171e05b4d2f6 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
* corelib: Gather string constants in central placeChristian Kandeler2017-11-291-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The same string literals appeared over and over again in the code base, causing redundancy in the sources as well as at run-time. We now give them a name and make sure they get instantiated at most once. String literals that occur only once are converted from QLatin1String to QStringLiteral unless they appear only in contexts that make use of QLatin1String overloads or they are clearly outside of any hot code paths. This seems to result in small, but measurable performance improvements, even if we assume the 1% changes to be noise: ========== Performance data for Resolving ========== Old instruction count: 3266514138 New instruction count: 3209355927 Relative change: -2 % Old peak memory usage: 29649896 Bytes New peak memory usage: 29436264 Bytes Relative change: -1 % ========== Performance data for Rule Execution ========== Old instruction count: 3367804753 New instruction count: 3319029596 Relative change: -2 % Old peak memory usage: 19577760 Bytes New peak memory usage: 19091328 Bytes Relative change: -3 % ========== Performance data for Null Build ========== Old instruction count: 608946535 New instruction count: 604566001 Relative change: -1 % Old peak memory usage: 14606384 Bytes New peak memory usage: 14579936 Bytes Relative change: -1 % Change-Id: Ia055a52e0a4b6fe6fd0f1e7ba4bfa583cba1b0ef Reviewed-by: Jake Petroules <jake.petroules@qt.io>
* Fix handling of empty JS filesChristian Kandeler2017-11-061-1/+2
| | | | | | | We would crash on those. Change-Id: I06ddfacfcea53d7a65cbd30a1b697cf09e28b82d Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
* Use ScriptEngine in ScriptImporter instead of QScriptEngineJoerg Bornemann2017-01-101-1/+3
| | | | | | | | This ensures that the correct evaluate overloads are used in future commits. Change-Id: I761dfbd07d45836180132b306be0ed2e4a672d7d Reviewed-by: Jake Petroules <jake.petroules@qt.io>
* Change style of #includes of Qt headersJake Petroules2017-01-041-1/+1
| | | | | | | | | | | | | | | | By using q<lowercase>.h headers, we become more bootstrap-friendly, as no full syncqt is required any more. In the same go, prefix all includes with the module name. This helps grep-based analysis of which parts of Qt are used and where. It's also consistent with Qt's public headers (where syncqt enforces the style). Testdata and examples are excluded from the change, as they are not relevant for bootstrapping. Change-Id: I9539b1d795e87fca6e5fc6c91acbb775b79208d9 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io> Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
* Update license headersIikka Eklund2016-08-291-14/+23
| | | | | | | | | | Patch-set 2 includes *.cpp *.c Every source file needs to have up-to-date license headers in order to pass ci. Change-Id: Ie6e493097af6f7dd6a8adff170eb856f496e689e Reviewed-by: Jake Petroules <jake.petroules@qt.io>
* Revisit importing JS source codeJoerg Bornemann2016-05-101-0/+161
Import code without access to the activation object. Other script engines do not allow easy access to the activation object. The new import code evaluates the code to be imported in an anonymous function that returns an object containing all variables and functions that are declared on the top level. E.g. importing the following snippet var greeting = 'hey!'; function upperCaseGreeting() { return "HEY!"; } is evaluated as (function () { var greeting = 'hey!'; function upperCaseGreeting() { return "HEY!"; } return { greeting : greeting, upperCaseGreeting : upperCaseGreeting } })() This has the following advantages: - Imported JS files do not see variables/functions anymore that were defined in already imported JS files. - No specialities of QScriptEngine are used. Porting to another JS engine becomes easier. - The clearing of the import cache before evaluation of every rule can be removed which improves the performance of rule execution by 28 % (according to qbs_benchmarker). Change-Id: I2f635c3375a137a96c27abf89d04a27fdf2c3f23 Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>