PureBasic 6.40 alpha 1 is ready, surprise inside !
Posted: Fri Jan 23, 2026 10:47 am
Hi everyone !
That's it, we finally decided to rework the internal stringmanager from the ground up ! The stringmanager hasn't changed since the PureBasic
creation almost 30 years ago, so it wasn't an easy decision to make because major modification for the compilers were needed and all the functions returning a string were impacted. But it's here with the 6.40 alpha 1, only available for the C back-end on Windows x64. The idea is to validate the new stringmanager to see if there is any showstopper before porting the modification to the x86 and x64 asm compilers which will takes time.
I will share some internal information about it:
- It should be 99% backward compatible. We will discuss edge case below.
- All strings are now prefixed by their length (except the strings in DataSection). The last bit of this prefix is used for a temporary flag.
That means than all string operation will have instant length information resulting in faster operation as iterating byte by byte on the string to find the null terminated char is no more needed.
The strings are still null terminated, so no change are needed in client code.
- Still no garbage collector
- The string manager doesn't have a per thread shared buffer anymore for temporary strings. That means there is no global variable to save the current position and the thread mode will have no performance hit. All is now done as new temporary string which will be used as final string if assigned. That removes useless string copy and is much more streamlined.
Example:
Old:
New:
It's a very basic case, but it shows the improvement by avoiding useless string copy and global variable preservation
- Optimized procedure parameters passing. If a string parameter isn't modified in the procedure, it will not be duplicated in the procedure. For example
Here the a$ and b$ are just referenced and won't be duplicated. In the older system, all the string parameters were duplicated.
Even better, the procedure 'a()' will return a temporary string which will be directly assigned to Result$ (no extra allocation/copy):
Here are the case where the parameters will be duplicated
- The string functions don't have an hidden parameter anymore, allowing better code generation
c$ = Str(150)
Old:
New:
- For PureBasic function returning a string, it's possible to tag a parameter as 'reusable' to avoid extra allocation when a temporary string is passed. For now, only LCase() and UCase() uses this, but it greatly improves their performances:
Ex:
The allocation is done when concatenating 'b$' + 'c$', then the UCase() function directly change the buffer with upper case character and returns the same buffer which is assigned to a$. So only one allocation occurred and no extra copy were performed.
- The 'mimalloc' memory manager has been integrated in PureBasic for all dynamic allocation to have a very fast and optimized memory allocator for all internal functions. More info here: https://github.com/microsoft/mimalloc
- Overall the performances should be much better, but there will be probably some case were it won't ! Feel free to test it and bench it with your own code (my speed test suite show major improvement (up to 10x) on most tests). For example this one is 9x faster:
- Edge cases:
We tried to do the migration as painless as possible, but there is some case where code change will be required. Basically if you patch a string by putting a zero in it, the Len() function will be wrong, and the concat functions will fail. You will need to use PeekS() for this.
You can take a look to the needed modification for the IDE to work with the new stringmanager, it's very light: https://github.com/fantaisie-software/p ... /344/files
Using Win32 API with Space() for example will require an extra PeekS(). If you find other issues, don't hesitate to share it, so I can take a look if it can be addressed or not.
We hope this major rework will increase the PureBasic app efficiency. Don't hesitate to test it but don't use this build in prod, it's indeed not production ready yet !
Have fun,
The Fantaisie Software Team
That's it, we finally decided to rework the internal stringmanager from the ground up ! The stringmanager hasn't changed since the PureBasic
creation almost 30 years ago, so it wasn't an easy decision to make because major modification for the compilers were needed and all the functions returning a string were impacted. But it's here with the 6.40 alpha 1, only available for the C back-end on Windows x64. The idea is to validate the new stringmanager to see if there is any showstopper before porting the modification to the x86 and x64 asm compilers which will takes time.
I will share some internal information about it:
- It should be 99% backward compatible. We will discuss edge case below.
- All strings are now prefixed by their length (except the strings in DataSection). The last bit of this prefix is used for a temporary flag.
That means than all string operation will have instant length information resulting in faster operation as iterating byte by byte on the string to find the null terminated char is no more needed.
The strings are still null terminated, so no change are needed in client code.
- Still no garbage collector
- The string manager doesn't have a per thread shared buffer anymore for temporary strings. That means there is no global variable to save the current position and the thread mode will have no performance hit. All is now done as new temporary string which will be used as final string if assigned. That removes useless string copy and is much more streamlined.
Example:
Code: Select all
a$ = b$+c$Code: Select all
SYS_PushStringBasePosition(); // current position in the shared buffer is saved (costly in threaded mode)
SYS_CopyString(v_bS); // string is copied on the per thread shared buffer
SYS_CopyString(v_cS);
SYS_AllocateString4(&v_aS,SYS_PopStringBasePosition()); // Position is restored and string is allocatedCode: Select all
s1=SYS_ConcatString(v_cS,v_bS); // A temporary string is created here
SYS_NewString(&v_aS,s1); // The temporary string is directly used (temporary bit removed)- Optimized procedure parameters passing. If a string parameter isn't modified in the procedure, it will not be duplicated in the procedure. For example
Code: Select all
Procedure.s a(a$, b$)
ProcedureReturn UCase(a$) + LCase(b$)
EndProcedureEven better, the procedure 'a()' will return a temporary string which will be directly assigned to Result$ (no extra allocation/copy):
Code: Select all
Result$ = a("Hello", "World")Code: Select all
Procedure.s a(a$, b$)
a$ = "-"+a$ ; Here, the a$ will be duplicated at procedure start, as it's modified.
ProcedureReturn UCase(a$) + LCase(b$)
EndProcedure
Procedure.s a(a$, b$)
*Cursor = @a$ ; Will also be duplicated as getting the pointer allow modification
ProcedureReturn UCase(a$) + LCase(b$)
EndProcedurec$ = Str(150)
Old:
Code: Select all
SYS_PushStringBasePosition();
SYS_PushStringBasePosition();
PB_Str(150LL,SYS_PopStringBasePosition());
SYS_AllocateString4(&v_cS,SYS_PopStringBasePosition());Code: Select all
void *r5=PB_Str(150LL);
SYS_NewString(&v_cS,r5);Ex:
Code: Select all
a$ = UCase(b$ + c$)- The 'mimalloc' memory manager has been integrated in PureBasic for all dynamic allocation to have a very fast and optimized memory allocator for all internal functions. More info here: https://github.com/microsoft/mimalloc
- Overall the performances should be much better, but there will be probably some case were it won't ! Feel free to test it and bench it with your own code (my speed test suite show major improvement (up to 10x) on most tests). For example this one is 9x faster:
Code: Select all
Start = ElapsedMilliseconds()
a$ = "World WorldWorld WorldWorld WorldWorld WorldWorld WorldWorld WorldWorld WorldWorld WorldWorld WorldWorld WorldWorld WorldWorld WorldWorld WorldWorld WorldWorld WorldWorld WorldWorld WorldWorld WorldWorld WorldWorld WorldWorld WorldWorld WorldWorld WorldWorld World"
For l = 0 To 1000
b$ = b$ + a$
Next
PrintN("Final length = " + Str(Len(b$)))
PrintN("Large concat: "+Str(ElapsedMilliseconds() - Start) + " ms")We tried to do the migration as painless as possible, but there is some case where code change will be required. Basically if you patch a string by putting a zero in it, the Len() function will be wrong, and the concat functions will fail. You will need to use PeekS() for this.
You can take a look to the needed modification for the IDE to work with the new stringmanager, it's very light: https://github.com/fantaisie-software/p ... /344/files
Using Win32 API with Space() for example will require an extra PeekS(). If you find other issues, don't hesitate to share it, so I can take a look if it can be addressed or not.
We hope this major rework will increase the PureBasic app efficiency. Don't hesitate to test it but don't use this build in prod, it's indeed not production ready yet !
Have fun,
The Fantaisie Software Team