Skip to content

Commit 0f6481b

Browse files
committed
Changed a sufficient stack size
1 parent d6b6665 commit 0f6481b

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/MsieJavaScriptEngine/ScriptDispatcher.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using System.Collections.Generic;
33
using System.Threading;
44

5+
using MsieJavaScriptEngine.Utilities;
6+
57
namespace MsieJavaScriptEngine
68
{
79
/// <summary>
@@ -11,9 +13,14 @@ internal sealed class ScriptDispatcher : IDisposable
1113
{
1214
#if !NETSTANDARD1_3
1315
/// <summary>
14-
/// The stack size is sufficient to run the code of modern JavaScript libraries
16+
/// The stack size is sufficient to run the code of modern JavaScript libraries in 32-bit process
1517
/// </summary>
16-
const int SUFFICIENT_STACK_SIZE = 2 * 1024 * 1024;
18+
const int STACK_SIZE_32 = 492 * 1024; // like 32-bit Node.js
19+
20+
/// <summary>
21+
/// The stack size is sufficient to run the code of modern JavaScript libraries in 64-bit process
22+
/// </summary>
23+
const int STACK_SIZE_64 = 984 * 1024; // like 64-bit Node.js
1724

1825
#endif
1926
/// <summary>
@@ -29,7 +36,7 @@ internal sealed class ScriptDispatcher : IDisposable
2936
/// <summary>
3037
/// Queue of script tasks
3138
/// </summary>
32-
private Queue<ScriptTask> _taskQueue = new Queue<ScriptTask>();
39+
private readonly Queue<ScriptTask> _taskQueue = new Queue<ScriptTask>();
3340

3441
/// <summary>
3542
/// Synchronizer of script task queue
@@ -50,7 +57,9 @@ public ScriptDispatcher()
5057
#if NETSTANDARD1_3
5158
_thread = new Thread(StartThread)
5259
#else
53-
_thread = new Thread(StartThread, SUFFICIENT_STACK_SIZE)
60+
int sufficientStackSize = Utils.Is64BitProcess() ? STACK_SIZE_64 : STACK_SIZE_32;
61+
62+
_thread = new Thread(StartThread, sufficientStackSize)
5463
#endif
5564
{
5665
IsBackground = true

0 commit comments

Comments
 (0)