-
Content Count
1372 -
Joined
-
Last visited
-
Days Won
130
Posts posted by Stefan Glienke
-
-
3 hours ago, Clément said:Is it even possible to improve the compiler as much?
Yes, you can improve the compiler (the language) as much as that it is partially safe to access raw memory without copying it - google for: .NET Span<T>
I did some experiments with it in Delphi and it improved some string parsing code that did not have to allocate new strings but also did not have to work with raw and rather unsafe PChar.
See https://bitbucket.org/snippets/sglienke/7e6xoe/span - this however cannot do what the C# compiler can do with ref (ensure that it only lives on the stack to not lives longer than what it refers to and these things) plus C# has readonly ref - basically a readonly pointer.
- 1
-
46 minutes ago, dummzeuch said:Do you know an analizer that finds this kind of problems?
Probably not for Delphi because there is virtually no market but you would be surprised what static code analysis can do.
-
7 minutes ago, dummzeuch said:Not sure what kind of code analyzer would have spotted that problem.
Simple, one that knows that you are pointing to an array element and sees that you are resizing the array thus invalidating this pointer.
-
-
No, unless you reference the helper type itself somewhere which you typically don't and if you do you can just register the function somewhere so you don't need to use RTTI.
-
No, consts are consts and no types (even if nested in types) hence no RTTI
Whatever you are trying you are probably better using something like DelphiAST and include that into your build process to generate something from source.
-
@Emil Mustea You could be that clever however the real runtime overhead of the spring smart pointer is so small that any such tricks are not necessary imo and rather lead to defects because of implicit variables as shown earlier.
@pyscripter YMMV but when I compile with release config the results are within 2% difference. Depending on order and CPU caching in that micro-benchmark they are even equal.
- 1
-
6 hours ago, Hallvard Vassbotn said:they should have been implemented as out-params
That would have caused a ton of unnecessary extra initializations because of out param.
If the compiler would actually be clever and detect them and omit when unnecessary I would agree.
Also if it would not be that terrible it could actually give the warning regardless the internal working of the parameter.
-
The ISafeGuard approach is not a smartpointer but creating a scope to some resource. There is a important difference: a smart pointer combines the resource and its lifetime management into one entity.
Also the record based approach is the most naive one - while Spring4D offers this one as well it has a more advanced one.
As for performance: measure it yourself:
program MeasureIt; {$APPTYPE CONSOLE} uses Spring, Diagnostics, Classes, SysUtils, JclSysUtils; const ADD_COUNT = 10; CREATE_COUNT = 100000; procedure MeasureSpring; var s: IShared<TStringList>; i: Integer; begin s := Shared.Make(TStringList.Create); for i := 1 to ADD_COUNT do s.Add(i.ToString); end; procedure MeasureJcl; var s: TStringList; g: ISafeGuard; i: Integer; begin s := TStringList.Create; Guard(s, g); for i := 1 to ADD_COUNT do s.Add(i.ToString); end; procedure MeasureClassic; var s: TStringList; i: Integer; begin s := TStringList.Create; try for i := 1 to ADD_COUNT do s.Add(i.ToString); finally s.Free; end; end; procedure Main; var sw: TStopwatch; i: Integer; begin sw := TStopwatch.StartNew; for i := 1 to CREATE_COUNT do MeasureSpring; Writeln(sw.ElapsedMilliseconds); sw := TStopwatch.StartNew; for i := 1 to CREATE_COUNT do MeasureJcl; Writeln(sw.ElapsedMilliseconds); sw := TStopwatch.StartNew; for i := 1 to CREATE_COUNT do MeasureClassic; Writeln(sw.ElapsedMilliseconds); end; begin Main; Readln; end.
The implementation in Spring 1.2.2 (currently released version) uses very optimized code for the smart pointer itself avoiding the overhead of an object allocation and all the code associated with it but only allocates a 12 Byte (32bit) block with the IMT. Since IShared<T> is not a regular interface but an anonymous method you can directly access the members of the underlying type. Yes, there is a method call every time but as you can measure that does not cause any significant overhead (unless you call .Add a million times). And even then the actual work being performed totally outweighs the smart pointer overhead
- 4
- 2
-
4 minutes ago, jbg said:compiler runs in the main thread and every time it updates the progress dialog it "pauses" the compilation
*facepalm*
-
The patches that went in 10.3 are mostly IDE related and not compiler related afaik.
Also from a few comments about the progress dialog alone affecting the duration of the compilation I have the strange feeling that inside the IDE the progress callback is wired a bit wrong (synchronous instead of asynchronous) causing unnecessary extra slowdown.
-
You, the container only is responsible for singleton lifetime
-
7 hours ago, Primož Gabrijelčič said:IFDEF against features
If possible - often enough you ifdef because of bugs or workarounds. I usually ifdef using the defines from jedi.inc and put a comment to the reported issue that I ifdef for.
- 2
-
Your question shows your lack of knowledge on the topic (I don't mean that in any form negative) so I suggest you should not mess with it.
RTTI is queried with code that executes at runtime and thus can only cause errors at runtime.
And even if you in your code don't explicitly make use of RTTI that does not mean that any other part might not do it (either third party or even RTL).
Want to serialize some object to JSON and use System.Json - ohh, will not work if you did disable RTTI (just one example).
So unless you really have a problem because of binary size (and no, we are most likely not in a 64k demo scene competition here) then apply the first rule of optimization by Michael A. Jackson: "Don't do it."
- 3
-
The R in RTTI is for runtime - now please guess 😉
-
Eye candy goes hand in hand with UX. If the usability sucks people will notice. If the UX is great but the UI is a bit dated people that are actually using it won't complain (much) but new users might pass by just because the first impression is not great visually. If all you got though is eye candy it might draw people but then let them down by crappy UX.
- 3
-
3 minutes ago, dummzeuch said:I need that high performance timer code I have got somewhere ..
System.Diagnostics.TStopwatch
- 1
-
If _UStrArrayClr is giving you an AV I am putting all my money on passing something wrong somewhere and destroying it's reference counter causing a premature FreeMem or something similar.
-
It's easy enough to profile where the mass of heap allocations are coming from by using FastMM full debug and log the callstacks.
Or run under SamplingProfiler and check what hits the memory routines most.
- 1
-
@Attila Kovacs Your quote from the help is kinda misleading because the code path there is the one handling the function not succeeding but returning ERROR_INSUFFICIENT_BUFFER.
@Kryvich The help combined with the code below is confusing me. It says number of bytes but then it also does a dwSize/sizeof(WCHAR) to allocate a wchar array 😕
-
If you're interested, look there - otherwise too much noise for a forum imo.
- 1
-
-
On 11/25/2018 at 10:43 AM, Dalija Prasnikar said:AFAIK this issue (limited debugging) has been reported
Yup, did that.
To work around that issue, you can put list.List into the watches.
- 2
-
What exactly do you do, what you posted is a private method that obviously gets called from another public method. Please show your code.
Unresponsive IDE and massive memory leaks with RIO
in Delphi IDE and APIs
Posted · Edited by Stefan Glienke
@Stéphane Wierzbicki @Attila Kovacs You should learn what procmon is telling there - all these attempted createfile are results of checking if the file exists and all the directories are obviously directories in the library path as a result of installing several third party components. And due to the way Delphi handles library/search paths when compiling (iterating them looking for the requested file and trying them with any possible unit scope - that is why you see it trying Vcl.Shell.blabla there, because usually Vcl.Shell is one of the unit scopes being put into a VCL project) this is what you get - nothing unusual there.