For Each, Every, Map etc, when maxthreads=1, disable parallel and reuse pageContext

Description

arrayEach much slower than for example a for loop because it creates a Pagecontext object for every thread created, that seems unnecessary, take this example

myArr = []; for( i=1; i<=50000; i++ ) { myArr.append( i ); } start=getTickCount(); max=arrayLen(myArr); for(i=1;i<=max;i++) {i=i;} dump(getTickCount()-start); start=getTickCount(); myArr.each( (i) => i=i, false, 20 ); dump(getTickCount()-start); start=getTickCount(); myArr.each( (i) => i=i, true, 20 ); dump(getTickCount()-start);

Environment

None

Activity

Show:

Pothys - MitrahSoft 22 March 2024 at 11:43

I've checked this ticket with Lucee 6.0.2.1-SNAPSHOT. Now, Each.java doesn't throw an NPE, and the issue has been resolved.
Here's the commit link : https://github.com/lucee/Lucee/commit/ef166cafae9f0a3418018ab54c48cb33d969d25d

Zac Spitzer 18 March 2024 at 16:27

this causes a NPE running docs

[java] [script] "}],"ErrorCode":"0","type":"java.lang.NullPointerException","StackTrace":"lucee.runtime.exp.NativeException: java.lang.NullPointerException [java] [script] at lucee.runtime.functions.closure.Each.afterCall(Each.java:160) [java] [script] at lucee.runtime.functions.closure.Each._call(Each.java:143) [java] [script] at lucee.runtime.functions.closure.Each.call(Each.java:66) [java] [script] at spelling.spellchecker_cfc$cf.udfCall1(/api/spelling/spellChecker.cfc:152) [java] [script] at spelling.spellchecker_cfc$cf.udfCall(/api/spelling/spellChecker.cfc) [java] [script] at lucee.runtime.type.UDFImpl.implementation(UDFImpl.java:112)

https://github.com/lucee/Lucee/pull/2337

Michael Offner 9 February 2024 at 09:02

Zac Spitzer 9 August 2022 at 07:54

one thing to keep in mind when addressing this, getCookie isn’t thread safe https://luceeserver.atlassian.net/browse/LDEV-4135

Zac Spitzer 5 March 2021 at 14:15

It’s slower because with parallel, Lucee provides a fresh pageContext for each execution, which does creates more overhead.

We won’t be merging my proposed change, as there could be situations where developer need/expect a fresh page context each time, despite only using one thread.

Fixed

Details

Assignee

Reporter

Priority

Fix versions

New Issue warning screen

Before you create a new Issue, please post to the mailing list first https://dev.lucee.org

Once the issue has been verified, one of the Lucee team will ask you to file an issue

Created 3 April 2020 at 14:55
Updated 23 January 2025 at 17:05
Resolved 22 March 2024 at 11:43

Flag notifications