PureBasic 6.40 alpha 1 is ready, surprise inside !

Developed or developing a new product in PureBasic? Tell the world about it.
Fred
Administrator
Administrator
Posts: 18453
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

PureBasic 6.40 alpha 1 is ready, surprise inside !

Post by Fred »

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:

Code: Select all

a$ = b$+c$
Old:

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 allocated
New:

Code: 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)
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

Code: Select all

Procedure.s a(a$, b$)
  ProcedureReturn UCase(a$) + LCase(b$)
EndProcedure
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):

Code: Select all

Result$ = a("Hello", "World")
Here are the case where the parameters will be duplicated

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$)
EndProcedure
- The string functions don't have an hidden parameter anymore, allowing better code generation

c$ = Str(150)

Old:

Code: Select all

SYS_PushStringBasePosition();
SYS_PushStringBasePosition();
PB_Str(150LL,SYS_PopStringBasePosition());
SYS_AllocateString4(&v_cS,SYS_PopStringBasePosition());
New:

Code: Select all

void *r5=PB_Str(150LL);
SYS_NewString(&v_cS,r5);
- 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:

Code: Select all

a$ = UCase(b$ + c$)
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:

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")
- 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
User avatar
jacdelad
Addict
Addict
Posts: 2062
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Post by jacdelad »

What a surprise! Now I know what to do this weekend! :D
Thanks Fred!
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/2*DX517, 164TB+82TB+28TB+2TB SSD
threedslider
Enthusiast
Enthusiast
Posts: 551
Joined: Sat Feb 12, 2022 7:15 pm

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Post by threedslider »

Much appreciated for a lot of info ! Thanks to bright a new beta :shock:
User avatar
jacdelad
Addict
Addict
Posts: 2062
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Post by jacdelad »

Btw, the downloads are labeled as "Beta 1", but that's just a sidenote.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/2*DX517, 164TB+82TB+28TB+2TB SSD
miso
Enthusiast
Enthusiast
Posts: 663
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Post by miso »

Sounds good! Thanks. Will test it.
User avatar
Kiffi
Addict
Addict
Posts: 1515
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Post by Kiffi »

Excellent news! :D
Hygge
threedslider
Enthusiast
Enthusiast
Posts: 551
Joined: Sat Feb 12, 2022 7:15 pm

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Post by threedslider »

jacdelad wrote: Fri Jan 23, 2026 11:43 am Btw, the downloads are labeled as "Beta 1", but that's just a sidenote.
Beta is correct for me because it is a user testing instead alpha is inside to organization for testing.
User avatar
GeoTrail
Addict
Addict
Posts: 2799
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Post by GeoTrail »

That looks very exiting.
Now I got something interesting to test during the weekend 😄
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
Sergey
User
User
Posts: 78
Joined: Wed Jan 12, 2022 2:41 pm

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Post by Sergey »

Amazing! We are waiting for an increase in productivity!
PB630 77ms vs PB640a1 8ms

After installining PB640a1 Winx64 in Compiler Options I see:
PureBasic 6.40 alpha 1 - C Backend (Windows - x64)
C:\Program Files\PureBasic\Compilers\pbcompiler.exe

And PureBasic 6.21 is missing and it is not even in the museum
User avatar
skywalk
Addict
Addict
Posts: 4287
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Post by skywalk »

WOW!
Can't wait to try.
I have a 40k line csv that I write into SQLite db using memory appends cause the concatenate was forever.
Will it fail if multithreading is enabled?
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
GeoTrail
Addict
Addict
Posts: 2799
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Post by GeoTrail »

Btw Fred, The download page says it's V 6.4 Beta 1, but in PureBasic it says 6.4 Alpha 1, and it says there's a new version when opening 6.4 Alpha and that the new version is v6.4 beta 1 :)
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
threedslider
Enthusiast
Enthusiast
Posts: 551
Joined: Sat Feb 12, 2022 7:15 pm

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Post by threedslider »

GeoTrail wrote: Fri Jan 23, 2026 1:20 pm Btw Fred, The download page says it's V 6.4 Beta 1, but in PureBasic it says 6.4 Alpha 1, and it says there's a new version when opening 6.4 Alpha and that the new version is v6.4 beta 1 :)
Yeah, I think from say to Fred with Alpha is correct as well because he exposes his feature to get a feedback before to put Beta to get real system that confuse to many us :shock: :mrgreen:

So let's clear, Alpha is for Fred and Beta is for us, simple, right ?
User avatar
GeoTrail
Addict
Addict
Posts: 2799
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Post by GeoTrail »

threedslider wrote: Fri Jan 23, 2026 1:30 pm
GeoTrail wrote: Fri Jan 23, 2026 1:20 pm Btw Fred, The download page says it's V 6.4 Beta 1, but in PureBasic it says 6.4 Alpha 1, and it says there's a new version when opening 6.4 Alpha and that the new version is v6.4 beta 1 :)
Yeah, I think from say to Fred with Alpha is correct as well because he exposes his feature to get a feedback before to put Beta to get real system that confuse to many us :shock: :mrgreen:

So let's clear, Alpha is for Fred and Beta is for us, simple, right ?
I get it. I think. Maybe 🤪😂 no I don't 🤯😂
But I'm not complaining, I never do. 🥳
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
threedslider
Enthusiast
Enthusiast
Posts: 551
Joined: Sat Feb 12, 2022 7:15 pm

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Post by threedslider »

GeoTrail wrote: Fri Jan 23, 2026 1:48 pm I get it. I think. Maybe 🤪😂 no I don't 🤯😂
But I'm not complaining, I never do. 🥳
Don't worry, it is up to Fred if he wants to make alpha or beta because Alpha can make public too but as i say before Alpha is more way for private working... so forget it that, all we want is an app testing for us :mrgreen:
Fred
Administrator
Administrator
Posts: 18453
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: PureBasic 6.40 alpha 1 is ready, surprise inside !

Post by Fred »

It's only the website which is wrong, the working link for alpha 1 is 'Download PureBasic 6.40 Beta 1 for Windows (x64)'. We usually don't do alpha so I won't change the website just for this time :)

@Skywalk: all should work (except the Purifier and some debugger stuff). The IDE is compiled with the 6.40 version, with threadsafe switch.
Post Reply